Script on Control Node Doesn't Run

Godot Version

v4.1.2.stable.official [399c9dc39]


If I create a new Control node for a UI element, attach a script with print statements in the _ready() function, and instantiate it in my World scene (Either a direct child or a child of a CanvasLayer), the script does not run and nothing is printed.

If instead I instantiate the node on my Player scene, rather than the world, the script runs perfectly fine and displays the print statements.

Other node scripts all work fine in my World scene, just not Control nodes. Could there be a setting configured in my World scene that’s causing this?

Thanks in advance!

1 Like

Are you sure that the node you inserted has the script correctly asociated?
If you do, could you provide more information please?

I’m pretty confident I’ve attached the script correctly because I just put the Control node in a scene, instantiated the scene in both the World and the Player scenes - and only the one on the Player runs.

Here’s a screenshot of my very basic scene:
Screenshot 2023-12-19 at 6.50.16 AM

Here’s the script ( in root folder):

extends Control

func _ready():
	print("TEST UI")

Unfortunately I can only post one image, or I’d upload the world & player scene.

All seems to be ok. Anyways there are some caouses you might check:

  1. Check if the script you attached is the correct one
  2. Chek that the node is not paused
  3. Chek that the node ready signal gets called when the tree is not paused (procces property)

did you add_child(the_control_node)?

What do you mean by checking if the node is paused?

I instantiated via the UI, so I’m not positive that this is necessary?

Check the property tree.paused

instantiated is not add_child()
the reason why the _ready() block of code doesnt work because the node you instantiated is not ready inside the root tree because not add_child

check the remote tab, if the instantiated node without “add_child” actually there btw, if the _ready()'s code doesnt print, then the node shouldnt be there on remote tab

Thank you all for the help, I finally figured it out.
I’m not sure why, but my World scene is being duplicated every time I run it in a different folder, and I accidentally opened that scene instead. Since the other World scene was the primary, I wasn’t running the World scene I was adding the Control node too.
I don’t know why it’s being created still, but it all makes sense now.

Thanks again!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.