Table of Contents

Class Timer

A countdown timer.

Inheritance
Timer

Remarks

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 tree, it can be manually started with Timer.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 are affected by time_scale. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate or physics_ticks_per_second.

See Also

Properties

autostart

If 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.

var autostart : bool = false

Property Value

bool

Remarks

  • void set_autostart(bool value)
  • bool has_autostart

ignore_time_scale

If true, the timer will ignore time_scale and update with the real, elapsed time.

var ignore_time_scale : bool = false

Property Value

bool

Remarks

  • void set_ignore_time_scale(bool value)
  • bool is_ignoring_time_scale

one_shot

If true, the timer will stop after reaching the end. Otherwise, as by default, the timer will automatically restart.

var one_shot : bool = false

Property Value

bool

Remarks

  • void set_one_shot(bool value)
  • bool is_one_shot

paused

If true, the timer is paused. A paused timer does not process until this property is set back to false, even when Timer.start is called.

var paused : bool

Property Value

bool

Remarks

  • void set_paused(bool value)
  • bool is_paused

process_callback

Specifies when the timer is updated during the main loop (see TimerProcessCallback).

var process_callback : int = 1

Property Value

int

Remarks

  • void set_timer_process_callback(int value)
  • int get_timer_process_callback

time_left

The 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.

var time_left : float

Property Value

float

Remarks

wait_time

The time required for the timer to end, in seconds. This property can also be set every time Timer.start is called.

Note: Timers can only process once per physics or process frame (depending on the process_callback). 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 time_scale.

var wait_time : float = 1.0

Property Value

float

Remarks

  • void set_wait_time(float value)
  • float get_wait_time

Methods

is_stopped

Qualifiers: const

Returns true if the timer is stopped or has not started.

bool is_stopped

start(float)

Starts the timer, or resets the timer if it was started already. Fails if the timer is not inside the 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 start(float time_sec)

Parameters

time_sec float

stop

Stops the timer.

void stop

Events

timeout

Emitted when the timer reaches the end.

signal timeout