0 votes
func _process(_delta):
    yield(get_tree().create_timer(time),"timeout")
    _do_stuff()

Works perfectly well until I try to change or reload current scene. Then it returns this error: "Resumed function _process() after yield, but class instance is gone".

Is there any simple workaround?
I honestly like the simplicity of yield(get_tree().create_timer(time),"timeout")
Is there a method maybe to control it?

Thank you for your time!

Godot version 3.2.3
in Engine by (307 points)

1 Answer

0 votes
Best answer

Just made a simple one myself. In case somebody needs it:

var startCounter = false     #starts counting when true
var wait = 3.7     #you want your stuff in how many seconds
var a = 0     #counter variable

func _process(delta):

    #here you set the time limit (customize to your needs)
    #by setting startCounter to false, you reset timer

    if startCounter == false:
        a = 0
    else:
        if a < 10:
            a += 1 * delta


    #start the counter and do your stuff when counter equals your desired wait time
    #set startCounter to true or false to your needs

    startCounter = true
    if wait >= a:
        #do your stuff here
by (307 points)

You can also use a Timer node. gdthonking

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.