-
Notifications
You must be signed in to change notification settings - Fork 26
sync.gd Stuck at _ready() When Using Dynamic Agent Setup #55
Description
I'm working on a project where I reuse the same EvaluationMap for both game testing and AI agent training. Due to the complexity of the setup, I dynamically spawn game elements (such as props, flags, weapons, and agents, ...) after the map has been loaded, placing them at random positions, change properties, ... in code.
However, when I instantiate sync.gd, it gets stuck at the following line in older versions:
await get_tree().root.readyIn the current main branch, it now gets stuck at:
await get_parent().readyThis happens because the scene has already been fully set up and the ready signal has already fired by the time sync.gd is instantiated.
Proposed Fix
Instead of awaiting the ready signal, this issue can be resolved by using call_deferred() to delay the call to _initialize() until the next idle frame—after the current scene tree update is complete. Deferring the initialization ensures that all nodes (including dynamically added agents and dependencies) have finished their own _ready() methods, and the parent of this node is also fully initialized.
This guarantees that when _initialize() runs, all agents and required nodes are present and ready.