Table of Contents

Class Timer

Namespace
Godot
Assembly
GodotSharp.dll

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 WaitTime, it will emit the Timeout signal.

After a timer enters the tree, it can be manually started with Start(double). 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 CreateTimer(double, bool, bool, bool).

Note: Timers are affected by TimeScale. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate or PhysicsTicksPerSecond.

public class Timer : Node, IDisposable
Inheritance
Timer
Implements
Inherited Members

Constructors

Timer()

public Timer()

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.

public bool Autostart { get; set; }

Property Value

bool

OneShot

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

public bool OneShot { get; set; }

Property Value

bool

Paused

If true, the timer is paused. A paused timer does not process until this property is set back to false, even when Start(double) is called.

public bool Paused { get; set; }

Property Value

bool

ProcessCallback

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

public Timer.TimerProcessCallback ProcessCallback { get; set; }

Property Value

Timer.TimerProcessCallback

TimeLeft

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

public double TimeLeft { get; }

Property Value

double

WaitTime

The time required for the timer to end, in seconds. This property can also be set every time Start(double) is called.

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

public double WaitTime { get; set; }

Property Value

double

Methods

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsStopped()

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

public bool IsStopped()

Returns

bool

Start(double)

Starts the timer, if it was not started already. Fails if the timer is not inside the tree. If timeSec is greater than 0, this value is used for the WaitTime.

Note: This method does not resume a paused timer. See Paused.

public void Start(double timeSec = -1)

Parameters

timeSec double

Stop()

Stops the timer.

public void Stop()

Events

Timeout

Emitted when the timer reaches the end.

public event Action Timeout

Event Type

Action