How can I pause execution for a certain amount of time in Godot? I can't really find a clear answer.
How can I pause a Thread for some seconds in Godot?
8.9k Views Asked by MomoVR At
5
There are 5 best solutions below
0
On
One-liner:
yield(get_tree().create_timer(1), "timeout")
This will delay the execution of the following line for 1 second.
Usually I make this to a sleep() function for convenience:
func sleep(sec):
yield(get_tree().create_timer(sec), "timeout")
Call it with sleep(1) to delay 1 second.
0
On
I see different answers but an important aspect is not mentioned: would you like to have the thread blocked or waiting?
see related wiki page
Blocking way:
Thread.Sleep(1000);
Non-blocking:
await get_tree().create_timer(1).timeout
The equivalent of
Thread.Sleep(1000);for Godot isOS.DelayMsec(1000). The documentation says: