Topic was automatically imported from the old Question2Answer platform.
Asked By
d2clon
Disclaimer: new in Godot here. Some experience with Unity
I am doing the initialization of my scripts into the _ready() method.
But I am missing a method that is automatically called on each script after all the _ready() methods have finished for all the Nodes in the scene. I understand that this is when all the tree has been loaded.
The reason is that in the _ready() method I initialize the actual script’s internal state. But if I need to make some initialization, adjustments, and setup, into the scripts referenced by this one I need to be sure I do them after the _ready() method has finished on all that objects.
I see that this is the lifecycle of scripts in Godot:
I’m not aware of an in-built callback that fires in exactly the situation you’ve outlined (and, so far, I guess I’ve never needed one).
Since the _ready() function of the top-level scene will be the last to fire (only when all of its children are also ready), I guess you could get what you want by firing a signal from there and connecting other nodes to that signal as necessary.
I’d be interested to hear other ideas here, but that’s what comes to mind initially.
Had the exact same idea and never needed this functionality either.
Just gonna add that the root node (Viewport) already has such a signal to connect to
I know this is an old post, but to anyone looking up the same question and finding this, use _init() for this.
_init() will be called before _ready(), so you can use it for initializing the script’s internal state and then use _ready() for behaviours that rely on other objects having been initialized.