Last active
April 22, 2022 20:02
Godot Quick Tips 01: The create_timer() helper for waiting X seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
After get_tree().create_timer, should I free it later? Or it will auto be free ?
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
Juan is doing god's work with that inline timer
yumm