Timer
A countdown timer.
Description
TheTimer 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 itswait_time, it will emit thetimeout signal.
After a timer enters the tree, it can be manually started withstart(). A timer node is also started automatically ifautostart istrue
.
Without requiring much code, a timer node can be added and configured in the editor. Thetimeout 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, useSceneTree.create_timer().
Note: Timers are affected byEngine.time_scale. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate orEngine.physics_ticks_per_second.
Tutorials
Properties
| ||
| ||
| ||
| ||
|
Methods
stop() |
Signals
timeout()🔗
Emitted when the timer reaches the end.
Enumerations
enumTimerProcessCallback:🔗
TimerProcessCallbackTIMER_PROCESS_PHYSICS =0
Update the timer every physics process frame (seeNode.NOTIFICATION_INTERNAL_PHYSICS_PROCESS).
TimerProcessCallbackTIMER_PROCESS_IDLE =1
Update the timer every process (rendered) frame (seeNode.NOTIFICATION_INTERNAL_PROCESS).
Property Descriptions
boolhas_autostart()
Iftrue
, the timer will start immediately when it enters the scene tree.
Note: After the timer enters the tree, this property is automatically set tofalse
.
Note: This property does nothing when the timer is running in the editor.
boolis_ignoring_time_scale()
Iftrue
, the timer will ignoreEngine.time_scale and update with the real, elapsed time.
boolis_one_shot()
Iftrue
, the timer will stop after reaching the end. Otherwise, as by default, the timer will automatically restart.
boolis_paused()
Iftrue
, the timer is paused. A paused timer does not process until this property is set back tofalse
, even whenstart() is called.
TimerProcessCallbackprocess_callback =1
🔗
TimerProcessCallbackget_timer_process_callback()
Specifies when the timer is updated during the main loop (seeTimerProcessCallback).
floatget_time_left()
The timer's remaining time in seconds. This is always0
if the timer is stopped.
Note: This property is read-only and cannot be modified. It is based onwait_time.
floatget_wait_time()
The time required for the timer to end, in seconds. This property can also be set every timestart() is called.
Note: Timers can only process once per physics or process frame (depending on theprocess_callback). An unstable framerate may cause the timer to end inconsistently, which is especially noticeable if the wait time is lower than roughly0.05
seconds. For very short timers, it is recommended to write your own code instead of using aTimer node. Timers are also affected byEngine.time_scale.
Method Descriptions
Returnstrue
if the timer is stopped or has not started.
voidstart(time_sec:float = -1)🔗
Starts the timer, or resets the timer if it was started already. Fails if the timer is not inside the tree. Iftime_sec
is greater than0
, this value is used for thewait_time.
Note: This method does not resume a paused timer. Seepaused.
Stops the timer.