Skip to content

Timer

Periodic and one-shot countdown timer node for delayed actions and recurring intervals.

Type: TimerNode · Category: Core & 2D · Also found as: timer

The Inspector’s Timer section (saved in the scene as "timer"):

Setting Scene key Default
Duration duration 1 Seconds until timeout
Auto Start auto_start false Start counting when the scene starts
Loop loop false Start again after each timeout (otherwise it stops)

It raises timeout when the duration has passed and tick every frame while it runs. Connect them in the Inspector’s Signals section or from a script:

function Spawner:ready()
local timer = self.node:get_node("SpawnTimer") ---@type TimerNode
timer:timer_set_duration(2.0)
timer:timer_set_loop(true)
timer:connect("timeout", function() self:spawn_enemy() end)
timer:timer_start()
end

No reflected properties of its own: its settings are described above.

Plus the common properties every node has.

Call them on the node (self.node in its script, or self.node:get_node("path")). Every node also has the Node methods.

Connects a handler to one of this node’s events: tick (Every frame while the timer runs), timeout (The timer’s duration elapsed); the tree events; custom ones.

self.node:connect("tick", function(value, source) Log.info("tick") end)
  • event TimerNodeEvent|string
  • handler fun(value: any, source: TimerNode)

Returns integer id Connection id for disconnect

Starts or restarts the timer from zero.

local timer = self.node:get_node("Cooldown"); timer:timer_start()

Stops the timer.

self.node:get_node("Cooldown"):timer_stop()

Checks if the timer is actively running.

if self.node:get_node("Cooldown"):timer_is_running() then return end

Returns boolean

Gets the elapsed time in seconds since start.

local t = self.node:get_node("Cooldown"):timer_get_elapsed()

Returns number

Sets the timer expiration duration in seconds.

self.node:get_node("Cooldown"):timer_set_duration(0.5)
  • durationSec number

Sets whether the timer automatically restarts upon expiring.

self.node:get_node("SpawnTimer"):timer_set_loop(true)
  • loop boolean
{
"type": "TimerNode",
"name": "Timer",
"position": [
0,
0
]
}