Table of Contents

Class Timer

Namespace
Godot
Assembly
GodotSharp.dll

Counts down a specified interval and emits a signal on reaching 0. Can be set to repeat or "one-shot" mode.

Note: Timers are affected by TimeScale, a higher scale means quicker timeouts, and vice versa.

Note: To create a one-shot timer without instantiating a node, use CreateTimer(double, bool, bool, bool).

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

Constructors

Timer()

public Timer()

Properties

Autostart

If true, the timer will automatically start when entering the scene tree.

Note: This property is automatically set to false after the timer enters the scene tree and starts.

public bool Autostart { get; set; }

Property Value

bool

OneShot

If true, the timer will stop when reaching 0. If false, it will restart.

public bool OneShot { get; set; }

Property Value

bool

Paused

If true, the timer is paused and will not process until it is unpaused again, even if Start(double) is called.

public bool Paused { get; set; }

Property Value

bool

ProcessCallback

Processing callback. See Timer.TimerProcessCallback.

public Timer.TimerProcessCallback ProcessCallback { get; set; }

Property Value

Timer.TimerProcessCallback

TimeLeft

The timer's remaining time in seconds. Returns 0 if the timer is inactive.

Note: This value is read-only and cannot be set. It is based on WaitTime, which can be set using Start(double).

public double TimeLeft { get; }

Property Value

double

WaitTime

The wait time in seconds.

Note: Timers can only emit once per rendered frame at most (or once per physics frame if ProcessCallback is Physics). This means very low wait times (lower than 0.05 seconds) will behave in significantly different ways depending on the rendered framerate. For very low wait times, it is recommended to use a process loop in a script instead of using a Timer node. Timers are affected by TimeScale, a higher scale means quicker timeouts, and vice versa.

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.

public bool IsStopped()

Returns

bool

Start(double)

Starts the timer. Sets WaitTime to timeSec if time_sec > 0. This also resets the remaining time to WaitTime.

Note: This method will 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 0.

public event Action Timeout

Event Type

Action