+1 vote

Hi,
how can I create instances of Scenes or for example the TestCube when using a function that is run by another thread?
When I try to create an instance from a threaded function, the thread never finishes and stays active forever.

Here is a quick example (commenting out the line var testcube = TestCube.new() makes the script run without problems)

extends Node

var thread1 = Thread.new()
var thread2 = Thread.new() 

 func _ready():
    print("starting thread")
    thread1.start(self, "threadedFunction1")
    thread2.start(self, "threadedFunction2")
    print("waiting to finish")
    thread1.wait_to_finish()
    thread2.wait_to_finish()
    print("finished")

func threadedFunction1(var data):
    print("load testcube")
    var testcube = TestCube.new()
    call_deferred("done1")

func threadedFunction2(var data):
    print("doing something else")
    call_deferred("done2")

func done1():
    print("thread1 done")

func done2():
    print("thread2 done")

Thanks.

in Engine by (13 points)

Please log in or register to answer this question.

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.