Class reference
Timer
Inherits Node
A countdown timer.
Description
The Timer node is a countdown timer and is the simplest way to handle time-based logic in the engine. When a timer reaches the end of its wait_time, it will emit the timeout signal. After a timer enters the scene tree, it can be manually started with start(). A timer node is also started automatically if autostart is true. Without requiring much code, a timer node can be added and configured in the editor. The timeout signal it emits can also be connected through the Node dock in the editor:
func _on_timer_timeout():
print("Time to attack!")
Note: To create a one-shot timer without instantiating a node, use SceneTree.create_timer(). Note: Timers in Time mode are affected by Engine.time_scale. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate or Engine.physics_ticks_per_second.
Properties
bool autostart = false
bool autostart = falseIf true, the timer will start immediately when it enters the scene tree. Note: After the timer enters the tree, this property is automatically set to false. Note: This property does nothing when the timer is running in the editor.
bool ignore_time_scale = false
bool ignore_time_scale = falseIf true, the timer will ignore Engine.time_scale and update with the real, elapsed time.
bool one_shot = false
bool one_shot = falseIf true, the timer will stop after reaching the end. Otherwise, as by default, the timer will automatically restart.
bool paused
bool pausedIf true, the timer is paused. A paused timer does not process until this property is set back to false, even when start() is called. See also stop().
int process_callback = 1
int process_callback = 1Specifies when the timer is updated during the main loop.
int process_type = 0
int process_type = 0Specifies which units the timer uses to count. (see TimerProcessType).
float time_left
float time_leftThe timer's remaining time in seconds. This is always 0 if the timer is stopped. Note: This property is read-only and cannot be modified. It is based on wait_time.
float wait_time = 1.0
float wait_time = 1.0The time required for the timer to end, in seconds or frames. This property can also be set every time start() is called. Time mode uses floats while Frame mode only accepts and returns non-fractional numbers. Note: Timers can only process once per physics or process frame (depending on the process_callback). In Time mode, an unstable framerate may cause the timer to end inconsistently, which is especially noticeable if the wait time is lower than roughly 0.05 seconds. For very short timers, it is recommended to write your own code instead of using a Timer node. Timers are also affected by Engine.time_scale.
Methods
bool is_stopped() const
bool is_stopped() constReturns true if the timer is stopped or has not started.
void start(float time_sec = -1)
float time_sec = -1)Starts the timer, or resets the timer if it was started already. Fails if the timer is not inside the scene tree. If time_sec is greater than 0, this value is used for the wait_time. Note: This method does not resume a paused timer. See paused.
void stop()
Stops the timer. See also paused. Unlike start(), this can safely be called if the timer is not inside the scene tree. Note: Calling stop() does not emit the timeout signal, as the timer is not considered to have timed out. If this is desired, use $Timer.timeout.emit() after calling stop() to manually emit the signal.
Signals
timeout()
Emitted when the timer reaches the end.
Constants
TIMER_PROCESS_PHYSICS = 0
Update the timer every physics process frame (see Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS).
TIMER_PROCESS_IDLE = 1
Update the timer every process (rendered) frame (see Node.NOTIFICATION_INTERNAL_PROCESS).
TIMER_PROCESS_TYPE_TIME = 0
Timer works with seconds. In this mode the timer is affected by Engine.time_scale.
TIMER_PROCESS_TYPE_FRAMES = 1
Timer works with frames. Speed depends on the framerate. Accepts non-fractional values only.