How would I delay the execution of some code without stopping the current thread?

Godot Version

v4.2.1

Question

How would I delay execution of some code without stopping the current thread?

I am new to godot so I am not sure of what would be the best option, thanks!

Depends on what kind of delay you’re looking for

If you’re looking for a delay of a certain time I’d use a timer, with a callback on it, like so:

get_tree().create_timer(x).timeout.connect(_my_method)

If you just want to delay it until the next frame you can use _my_method.call_deferred()

Or you can use await, which doesn’t block the current thread

await get_tree().create_timer(x).timeout
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.