The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+2 votes

i heard you can't get function States from await like yield can. so is it even possible to do that anymore?

related to an answer for: How to use "await" in godot 4.0 ?
in Engine by (65 points)

1 Answer

+1 vote

As expected the outer function will wait for the inner function complition and will continue it's run afterwards.
Just tried it out, it is possible and it works.

about yield, from:

yield is now await
The yield keyword is removed in favor of await. You can use await somesignal which works the same as yield did before.
You can also do await my
func() which is the same as yield(myfunc(), "completed") but it also works if the function isn't a coroutine:
it'll just run synchronously and get the returned value. Note that if my
func() returns a signal, then it will wait for that signal to be emitted.

by (16 points)

Here's an example for those seeking:

func _ready():
    await a()

func a():
    await get_tree().create_timer(1).timeout
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.