Skip to content

Instantly share code, notes, and snippets.

@brunosxs
Last active April 22, 2022 20:02
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brunosxs/95c482c19573a582feb4e794655011f0 to your computer and use it in GitHub Desktop.
Save brunosxs/95c482c19573a582feb4e794655011f0 to your computer and use it in GitHub Desktop.
Godot Quick Tips 01: The create_timer() helper for waiting X seconds
# Available only in the 2.2 legacy branch and posterior versions
func _ready():
# The old way:
print("HELLO") # Code before the yield
# Setting up the yield:
var t = Timer.new() # Create a new Timer node
t.set_wait_time(5.5) # Set the wait time
add_child(t) # Add it to the node tree as the direct child
t.start() # Start it
yield(t, "timeout") # Finally, make the script stop with the yield
print("WORLD") # Code that will be exectued after the yield
print("=====")
# The optional new way:
print("HELLO AGAIN!") # Code before the yield
# Setting up the yield with the new function 'create_timer()':
yield(get_tree().create_timer(5.5),"timeout")
print("WORLD") # Code that will be exectued after the yield
Copy link

ghost commented Sep 13, 2017

Juan is doing god's work with that inline timer

yumm

@qichunren
Copy link

After get_tree().create_timer, should I free it later? Or it will auto be free ?

@silverweed
Copy link

Be aware that waiting on this timer won't pause if you call get_tree().paused = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment