To solve this issue, you can use a signal in the Parent script and connect it to the children scripts. Here’s a step-by-step solution:
In the Parent script, declare a signal at the top of the script:
signal ready_signal
In the _ready() function of the Parent script, emit the signal after setting up the array:
func _ready():
var array = [0, 1, 2, 3]
#... other setup code...
emit_signal("ready_signal")
In the Child script, create a function that will be called when the signal is emitted from the Parent script. This function can be called anything, e.g., _on_Parent_ready().
func _on_Parent_ready():
# This function will be called when the Parent script emits the ready_signal
# You can access the Parent script's variables and functions from here
pass
In the Child script, connect the ready_signal from the Parent script to the _on_Parent_ready() function using the connect function:
Now, in the Grandchildren script, you can access the Parent script’s variables and functions through the Child script. You can use the match statement as needed.
By using a signal, you ensure that the Child script waits for the Parent script to finish setting up before executing its own code. This way, you can access the Parent script’s variables and functions safely.
Remember to adjust the script names and function names according to your actual scene hierarchy.
Thank you for your detailed answer.
I simply had to change get_parent().connect(“ready_signal”, self, “_on_Parent_ready”) to
get_parent().connect(“ready_signal”, self._on_Parent_ready) I guess depending on the Godot version.
You don’t need a seperate signal. Each node emits a ready signal when ready.
And you don’t need to connect it. You can use await to stop further code execution until the ready signal gets emitted: