This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I have a script like this:

var _thread

func start():
    _thread = Thread.new()
    _thread.start(self, "_thread_func")

func _thread_func():
    pass

Fairly basic stuff.

But when my game runs and I reach the point where this code is run I get a background error. There's no stack trace for it, but it only appears when the line _thread.start(self, "_thread_func") is present. This is what I get when I hover over the error in the error box:

enter image description here

Type:Error
Description:
Time: <time>
C Error: Method/Function Failed.
C Source: core/bind/core_bind.cpp:1939
C Function: _start_func
in Engine by (291 points)
edited by

Aren't you missing () after func _thread_func? Also, can you try renaming _thread_func to something else.

The missing () was a typo. Just put those in.

1 Answer

+2 votes
Best answer

You need parentheses for function ().
And one parameter is need for thread function.

var _thread

func start():
    _thread = Thread.new()
    _thread.start(self, "_thread_func")

func _thread_func(userdata):
    # return for ending thread
    return 0
by (9,800 points)
selected by

I actually did have the parentheses for _thread_func, but was missing the userdata parameter. The thread started to work once I included the parameter.

Thanks for the help. I think both the documentation and the error needs to be more explicit that even if no userdata is expected, the function used in the thread needs to have at least one argument.

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 Frequently asked questions and 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 [email protected] with your username.