I am missing a lifecycle initialization method after _ready()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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:

This is the same in Unity:

As I am understanding the Godot’s _ready() is equivalent to the Awake() in Unity.

I am missing in Godot what would be the equivalent of Start() in Unity. Which is called after all the objects have been initialized.

Does this method exist? Is there a walk-around?

:bust_in_silhouette: Reply From: jgodfrey

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

So in the desired class

func start():
    pass

func _ready():
    get_tree().get_root().connect("ready", self, "start")

or optionally stall untill all ready’s are well . . . . . . . ready

yield(get_tree().get_root(), "ready")
# Do stuff after all ready and fully awake()

Wakatta | 2022-12-19 00:00