Skip to content

sync.gd Stuck at _ready() When Using Dynamic Agent Setup #55

@nongvantinh

Description

@nongvantinh

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.ready

In the current main branch, it now gets stuck at:

await get_parent().ready

This 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions