Timer
Periodic and one-shot countdown timer node for delayed actions and recurring intervals.
Type: TimerNode · Category: Core & 2D · Also found as: timer
Settings
Section titled “Settings”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()endProperties
Section titled “Properties”No reflected properties of its own: its settings are described above.
Plus the common properties every node has.
Lua methods
Section titled “Lua methods”Call them on the node (self.node in its script, or self.node:get_node("path")). Every node also has the Node methods.
TimerNode:connect(event, handler)
Section titled “TimerNode:connect(event, handler)”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)eventTimerNodeEvent|stringhandlerfun(value:any, source: TimerNode)
Returns integer id Connection id for disconnect
TimerNode:timer_start()
Section titled “TimerNode:timer_start()”Starts or restarts the timer from zero.
local timer = self.node:get_node("Cooldown"); timer:timer_start()TimerNode:timer_stop()
Section titled “TimerNode:timer_stop()”Stops the timer.
self.node:get_node("Cooldown"):timer_stop()TimerNode:timer_is_running()
Section titled “TimerNode:timer_is_running()”Checks if the timer is actively running.
if self.node:get_node("Cooldown"):timer_is_running() then return endReturns boolean
TimerNode:timer_get_elapsed()
Section titled “TimerNode:timer_get_elapsed()”Gets the elapsed time in seconds since start.
local t = self.node:get_node("Cooldown"):timer_get_elapsed()Returns number
TimerNode:timer_set_duration(durationSec)
Section titled “TimerNode:timer_set_duration(durationSec)”Sets the timer expiration duration in seconds.
self.node:get_node("Cooldown"):timer_set_duration(0.5)durationSecnumber
TimerNode:timer_set_loop(loop)
Section titled “TimerNode:timer_set_loop(loop)”Sets whether the timer automatically restarts upon expiring.
self.node:get_node("SpawnTimer"):timer_set_loop(true)loopboolean
In a scene file
Section titled “In a scene file”{ "type": "TimerNode", "name": "Timer", "position": [ 0, 0 ]}