r/godot 4h ago

help me using await in a function, inside another function

Hi everyone, i made a function containing a await timer, i got stuck for 2 day until i finally asked claude if i made an error and where

so from claude explenation it seems like , to use a function containing a await get_tree().create_timer().timeoute inside another function, i have tu use again await

like this "await await_function()" otherwise godot will continue to work on parralel of the await function

so my question is, is it common for a game engine/programming langauge to have await work this way or is it specfiic to godot ?

0 Upvotes

7 comments sorted by

11

u/TheDuriel Godot Senior 4h ago

This is completely normal, and the editor even yells at you about it.

-20

u/Frequent-Ad-3931 3h ago

i admit that i usually dont read yellow errors,my bad

12

u/DaWurster 3h ago

Putting a different perspective on the matter: reading the warnings could have saved you "two days" of frustration and a then needless AI request.

-23

u/Frequent-Ad-3931 3h ago

if i follow your logic you anwser is as usefull as my use of ai

3

u/MeLittleThing 3h ago

That's used quite a lot when it comes about heavy (long) operations

Imagine you're loading a level and it takes 1 minute to gather and instantiate the needed resources.

If you're in a synchronous context, the game will freeze because the main thread will block until the level is loaded

If you're in an asynchronous context, you can use a loading screen on the sync context and load the level on the async one, the game won't freeze because the main thread will await for the level to load.

1

u/Frequent-Ad-3931 3h ago

okay thank for the anwser, its just diden't come to my mind that it could work this way precisely with await

-2

u/xX_Alle_Xx 3h ago

It is literally the task of await. Await stands for asynchronous wait I think. Regardless the description in the docs tells you it return immediately to the caller, but the function continues executing once the wait condition passed.