My question is how does Godot know in which order to run the _ready functions and can I rely on everything just being there when I need it? I mean, it’s awesome that it works, but I don’t understand how
Here’s how the question came up:
I got an error which was not related to my code, but to a script not being attached to a node (don’t ask me how I managed to do that ), so I got this error:
Invalid call. Nonexistent function ‘update_GUI’ in base ‘Nil’.
This made immediate sense to me, because I was calling the function of a node whose _ready
has to be run to be registered globally so it can be called in another node’s _ready
function. I can’t tell Godot in which order the nodes should run their _ready
functions, so that’s the reason for the error, I thought.
But that’s not the case!
Here’s some code snippets to make the whole thing a little clearer, hopefully:
# Global
var GUI
# GUI
func _ready():
Global.GUI = self
# GameState
func _ready():
Global.GameState = self
lives = starting_lives
update_GUI()
func update_GUI():
Global.GUI.update_GUI(lives)