managing project/scene startup phases & object relations?

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

Not surprisingly there can quickly become a rat nest of relationships among things at the startup of a game, because often it is “easiest” / “best” / “most understandable” when things are positioned relative to each other.

The problem is then the order of creation and setup of things. Chicken and egg.

Probably not something that Godot/gdscript can solve, I have to make sure to work on structuring my app and code to handle this. Just looking for thoughts/experience other people have since I want to avoid creating a bad/brittle/nasty/confusing project.

concrete sub/related question: Does the Scene’s Tree control in what order “onready var” and “func _ready()” are called across all the nodes? If a node is higher in the Tree (visually in the gui that shows the tree) does it get those run before others?

If you start to rely on execution order, this is going to be a funny debugging session :smiley:

More seriously, I don’t really understand what concrete problem you have, I personally never had “chicken/egg” problems in Godot. Could you explain?

if _enter_tree() and _ready() are not enough to initialize your nodes, then you can still simulate an extra step one frame after by scheduling it for the next frame with yield(get_tree(), "idle_frame") in _ready(), just before the code requiring other nodes to be initialized. However it can become a mess really quickly and make it hard to debug.

I think the scene tree determines the order in which nodes are drawn, and possibly the order in which _ready() and _process() functions are called. However, I don’t like relying on it because it’s easy to get wrong. Let’s say you want to move some sprite above, but any mistake and boom, you also changed the order of execution and the game crashes.

This is only a comment because the subject is bit wide yet.

Zylann | 2016-09-30 01:23

thanks! yeah, i don’t want to create something very brittle, for sure. my use case was a debugging/testing/hacking thing that isn’t real world. so i am more just curious to learn in general. e.g. to learn how the order in the tree influences things.

raould | 2016-09-30 19:40