My custom scene's child node's ref is not initialized before I try to set its properties.Using *_defferd()? or?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kinori
I preloaded my custom scene, right after instantiating  it by code, I tried to set the properties of its instance. There's no problem if I just set the root node's properties.However, if I tend to set the child's node properties, it would not working and give me an error. After debugging, I made the assumption that I had problem with getting the referrence of the child node. Because I use "onready" to get the child node. It's before the root node go to ready stage that I try to set the properties. My ref would be null. So I tried to use *_defferd() function. It worked. But I wonder, is there a more elegant way to deal with this. Can I just get child node's referrence in a early stage. 

I do not konw when the child node is instantiated. Or maybe the child node’s instance has not been created at all when I try to access it.

:bust_in_silhouette: Reply From: Inces

I see You opened a double issue for your problem

I have to repeat and explain some more
First You preload scene.
at this moment all default values of introduced variables are set, except onready vars
Next You call instance()
at this moment init() is called
Finally you call add_child()
at this moment ready() is called and onready vars values are set

So after all this happened You can safely change properties of your instance. I suspect You have a conflicting code, setting property in ready() with some exported value and manually after instantiation using another value. I understand this is why You have to call_deferred() - to wait for ready function, so it won’t reset your manual value.

You just need to change this design :). Set properties for every objects consequently in one place, You just need to decide.