+3 votes

So, is there a built-in function to GDScript where I can pause a process in a script for a few seconds, say:

wait(1) #waits for 1 second
set_visible(true) #then continues the rest of the script after the 1 second wait
asked Aug 16, 2016 in Engine by apekke (24 points)
edited Aug 16, 2016 by Akien

3 Answers

+12 votes
Best answer


var t = Timer.new()
yield(t, "timeout")
answered Aug 16, 2016 by twinpixel (188 points)
selected Aug 17, 2016 by apekke

Don't forget to free the timer afterwards, or you'll cause a memory leak.

+2 votes
answered Aug 16, 2016 by Akien (1,843 points)

Note that if you use those in the main thread, those will cause the project to freeze until the delay has expired.

+4 votes
yield(get_tree().create_timer(1.0), "timeout")
answered Nov 9, 2018 by ttkhila (26 points)

Does the timer created here get disposed?

I believe that, once the routine has been resumed, the SceneTreeTimer object, returned by the create_timer () function, becomes invalid, as documented at:

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 How to use this Q&A? before posting your first questions.