_ready not called on script instance

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vonflyhighace2
:warning: Old Version Published before Godot 3 was released.

I’ve noticed that when i’m dealing with scripts that are instanced into a scene the _ready() method isn’t called, and instead _init() is the only thing that is. Is that by design or a bug?

did you add it as a child of a node that is in the scene? I think that’s when _ready() gets called

batmanasb | 2016-04-04 23:01

(I moved this comment to an answer)

Bojidar Marinov | 2016-04-05 14:19

I see. Makes sense now. What I was doing was setting a script on a node during run-time. by that point _ready had already been called on all child nodes.

vonflyhighace2 | 2016-04-05 18:57

:bust_in_silhouette: Reply From: duke_meister

_ready() is a function defined in Node, and so any class/script derived from it will also have it. So unless your script/class extends Node, just having a _ready() method doesn’t mean yours will get called. _init() is the constructor for your class, so it gets called regardless. I hope this is correct with my limited time with Godot (and without seeing any of your code).

That’s correct indeed.

Bojidar Marinov | 2016-04-05 14:14

:bust_in_silhouette: Reply From: Bojidar Marinov

Note that _ready is called when NOTIFICATION_READY is received, which happens only after all children have received it as well. This will not happen if you change scripts, in which case you might want to use notification(NOTIFICATION_READY) to send it again. Another option might be to listen for the script_changed signal.