Godot: SceneTreeTimer yield and resume on "timeout" doesn't work after the first yield

Created on 22 Feb 2018  路  5Comments  路  Source: godotengine/godot

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:

  1. Make a scene with any type of node as its root
  2. Write this code:
func _physics_process(delta):
    while true:
        yield(get_tree().create_timer(1), "timeout")
        print("time")
  1. Play the created scene.
  2. Notice how after the first "time", "time" gets printed really quickly without yielding for 1 second.

Notes
I'm aware that the while true is unnecessary (maybe even worse), but omitting the while true produces the same issue.

archived

Most helpful comment

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)
...

All 5 comments

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")
Was this page helpful?
0 / 5 - 0 ratings