0 votes

I'm not sure what I'm doing wrong, but I have something like this:

var thread

func game():
    loading_scene = loadinganimation.instance()
    thread.start(self, "heavy algorithm that emits finished when it's done")
    yield(self, "finished")
    #print("got past yield")
    game_scene = game.instance()

func _exit_tree():

The thing that I don't understand is that the game scene never loads. If I uncomment the print line, it prints, so I know it's not hanging at yield. If I directly call the function which I'm running on a separate thread, it runs (but causes the loading animation to freeze, which is why I'm taking it off the main thread to start with, it's quite a heavy algorithm). Putting thread.waittofinish after the yield line also does not do anything.

Why is running a function in another thread caused me to be unable to instance anything when I get back to the main thread?

in Engine by (251 points)

1 Answer

0 votes
Best answer

So, I found out what the issue was. For some unknown reason (any explanation is welcome), I had to use call_deferred to add the child, rather than calling it directly. I'm not sure why this small difference was so game-breaking, but there you go.

by (251 points)
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.