Menu
CoddyTech

Await a Timer

Part of the Game Rules section of Coddy's Godot journey. Lesson 5 of 29.

To wait once inside a function, you do not need a Timer node. get_tree().create_timer(2.0) makes a one shot timer in code that is already running. await pauses your function until its timeout signal arrives:

func _ready():
	print("Wait for it")
	await get_tree().create_timer(2.0).timeout
	print("Now!")

The first line prints at once. The function stops at await while the game keeps running. Two seconds later, the function carries on.

Keep .timeout at the end. await waits for a signal, and timeout is the signal.

challenge icon

Challenge

Easy

The gate opens as soon as the game starts. Make it open two seconds later. Await a two second timer before the line that opens it.

Try it yourself

extends Node2D

func _ready():
	$Gate.position.y -= 140
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Rules

Practice on your own: Godot playground