Godot Engine Quick Tips - 01: create_timer() helper for yielding a script

BrunoSXS published on
2 min, 202 words

Time icon]

Implemented during the middle of last year(or at least publicly announced by the devs) was a small but really useful feature that was overlooked by me at the time thanks to the rapid evolutionary pace of Godot, it is a an optional way to yield the script for an amount of time.

There are basically two ways of doing it: You could either create the timer in the editor and access it through code or you could create it all trough code at runtime as I did in the gist.

It essentially makes the 5 lines of code go down to 1, which helps a lot in code organization.

The only downside: It is not available on the stable branch yet(at the moment: 2.1.2) but you can get it on the 2.2-legacy branch or in the master branch of godot.

See the gist, from line 5 to 14 I wrote the code using the default way, and from line 21 to 23 we see the same thing with the new create_timer() function: