Skip to content

Conversation

@nongvantinh
Copy link

@nongvantinh nongvantinh commented Jun 14, 2025

Fixes: GH-55

Avoids waiting on already-fired ready signals by deferring _initialize() using call_deferred(). This ensures all dynamically added nodes and dependencies have completed their own _ready() methods before initialization.

Fixes: edbeechingGH-55

Avoids waiting on already-fired `ready` signals by deferring _initialize()
using `call_deferred()`. This ensures all dynamically added nodes and
dependencies have completed their own _ready() methods before initialization.
Copy link
Collaborator

@Ivan-267 Ivan-267 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello and thanks for this PR, I haven't tried it but the solution seems elegant. I'd like to do a brief test if I get some time on both Windows and Linux, but likely it will be fine.

There might be an edge case if some of the important nodes use "await frame/physics frame/etc" in their ready methods (or are otherwise not loaded within a single frame), but this case can also happen with the previous code.

For all such cases, there might be a simple alternate solution. One possible way might be to extend sync.gd in the project, override _ready() to do nothing (just return), then just call sync _initialize() from your game/scene manager node once the scene has fully loaded.

_initialize()
await get_tree().create_timer(1.0).timeout
get_tree().set_pause(false)
call_deferred("_try_initialize")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
call_deferred("_try_initialize")
_try_initialize.call_deferred()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants