Null on scene items

image

I have a scene (image) which is a sprite with 3 areas.
in the ready on parent (sprite) I connect to area signals mouse_enter.

afaik it creates the tree from bottom up so by the time func ready happens on root, all areas should be created. So in the root I used @ready var to set a reference to respective areas.

When I add this in design time it works fine however, it I add this during run time.
using class.new() I get failure on connect, citing that the areas are null (and if I looking remote) I can see they haven’t been created. I’m not sure why they arent’ created as part of the scene instance?

thanks for help

Hi! I don’t know why it happens, perhaps share the code running in NetworkNode. You can try to use get_node instead of @onready, e.g.:

var connectarea = null
func _ready():
	connectarea = get_node("ConnectArea")

and see if it works. I had a sitation too where I needed that a while ago.

Hey,
it depends when you are connecting indeed
The .new() doesn’t trigger the _ready builtin, it only call the _init one

The _ready builtin will be call when the scene enter the scene tree eg .add_child(node)

I do also think that a load is preferable when dealing with a scene instead of new

Hope that helped

1 Like