Godot version:
3.0
OS/device including version:
MacOSX
Issue description:
yield in _physics_process using the SceneTreeTimer resuming with a "timeout" signal doesn't work after the first yield
Steps to reproduce:
func _physics_process(delta):
while true:
yield(get_tree().create_timer(1), "timeout")
print("time")
Notes
I'm aware that the while true is unnecessary (maybe even worse), but omitting the while true produces the same issue.
Probably intended. _physics_process is called every physics frame and multiple SceneTreeTimers are created.
@Noshyaar that makes sense, but then wouldn't I be paused forever then?
I'm not sure I understand. Here's what I think is happening (let's make the delay 5 secs)
Physics frame 1: create timer 1, yield
Physics frame 2: create timer 2, yield
... repeating
... 5 seconds later
Timer 1: elapsed, resume, print "time" (if there's `while true`, create timer and yield again)
Timer 2: elapsed, resume, print "time" (same as above)
...
Oh, I see, I thought for some reason the last timer would get thrown away.
Yeah, I was too overzealous. Thanks!
Hey @Lucrecious, But why does the below code does not print "waiting has completed"?
extends Node
signal completed
export var n=3
func _ready() -> void:
print("waiting for 3 sec")
yield(counter(n, 2.0), "completed")
print("waiting has completed")
get_tree().quit()
func counter(n:int, wait:float):
while n>0:
print(n)
yield(get_tree().create_timer(wait), "timeout")
n-=1
emit_signal("completed")
Most helpful comment
I'm not sure I understand. Here's what I think is happening (let's make the delay 5 secs)