Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DavidPeterWorks |
Hi,
Some of my nodes dependent from other nodes. _ready is called but the dependent node is not initiated (not ready).
Is there any standard way to have a completed hierarchy so the dependent structures can setup?
I use ugly things like:
func _ready():
yield(get_tree().create_timer(0.1),"timeout")
superDependentCallsAndSetups()
Thank you,
David
What’s the relationship between the node with that script and the dependent node? Is it parent or child?
Dlean Jeans | 2019-06-04 10:12
Child modifies the behavior of the parent.
DavidPeterWorks | 2019-06-04 10:20
I’m not sure, but isn’t this a job for ‘signals’?
I know that every node in your tree emits a signal on ready. You should be able to trigger some function in your mother-node, whenever specific ready-signals have been received.
Ole | 2019-06-06 06:52
My solution turned out like this.
1, I added all of the dependent children nodes to a group “final_ready”.
2, I moved the scripts in the _ready() to a new method final_ready().
3, I call the call_group(“final_ready”) from the scene root in the _ready() function.
The result is that. I initialize all the dependent nodes after the whole scene structure is ready.
Is there any better solution?
DavidPeterWorks | 2019-06-06 08:00
The best solution would be to get rid of the dependency, and use dependency injection instead, as described in Scene organization — Godot Engine (3.1) documentation in English
But if this doesn’t work for whatever reason, your call_group solution looks fine.
Thomas Karcher | 2019-06-06 15:05