0 votes

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?

Godot version 3.5
in Engine by (46 points)

1 Answer

+2 votes
Best answer

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.

by (21,656 points)
selected by

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()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.