Godot Version
4.4.dev
This is a curious behavior with Timer that I ran into recently. I tried to check if a timer has finished during _physics_process by doing this:
func _physics_process(delta: float) -> void:
if $speak_timer.time_left==0:
but turns out this conditional is never true if you don’t manually stop the timer.
I had to instead try:
func _physics_process(delta: float) -> void:
if $speak_timer.time_left<0.1:
Anyone had similar issue?
update:
TL;DR use get_time_left().
This is how it’s implemented in the engine:
double Timer::get_time_left() const {
return time_left > 0 ? time_left : 0;
}
Turns out time_left will always be less than 0 when it’s stopped. This somewhat contradicts what’s been said in the doc.
The timer’s remaining time in seconds. This is always 0 if the timer is stopped.
well, actually it would be -1:
void Timer::stop() {
time_left = -1;
_set_process(false);
autostart = false;
}