How to resolve that the signal being waited for is emitted by code before it returns

Godot Version

godot 4.3 stable

Question

how to resolve that the signal being waited for is emitted by code before it returns.

I am not entirely sure I understand your question but this may help.

You can use call deferred to make sure the signal is sent at the end of the current frame like this.

call_deferred("emit_signal", "your_signal")

Or if that is not what you meant, then you can await a signal like this:

await some_object.your_signal

Or if that is not what you meant either, you may have to supply additional information so we can help.

Await in the docs:

Call deferred in the docs:

2 Likes
call_deferred("emit_signal", "your_signal")

As you say. call deferred is a relatively good choice.

Although its not as good as Promise in JS.

Thank you very much!

Promise and call_deferred() are completely different things, you can’t compare them directly.
If you want to have a promise-like functionality, you can await a coroutine that returns a value. Check here for more information about coroutines in Godot.

1 Like