0 votes

Hello!

I'm having some problems with thread execution.
After some debug i isolated the problem but i'm not sure why it's happening.

In my tests, this code works:

extends Node2D
var thread

func _ready():
    thread = Thread.new()
    thread.start(self, 'test1')

func test1(data):
    print('hey')
    return 0

This prints "hey" as expected.

However, this code doesn't prints "hey":

Main node:

extends Node2D
var Class = load('res://class.gd')

 func _ready():
    var c = Class.new()
    c.test1()

Class node:

var thread

func test1():
    thread = Thread.new()
    thread.start(self, 'test2')

func test2(data):
    print('hey')
    return 0

Instead, it gives me the error "ERROR: Could not call function 'test2'' starting thread ID: 4956 Reason: Method Not Found"
It seems it can't find the method in the instanced class. I tried others arguments instead of 'self' like the calling instance or sending the instance as argument from the calling instance.

Regards.

asked Jan 28, 2019 in Engine by katuiche (23 points)

1 Answer

0 votes
Best answer

I figured out what was the problem:
Only nodes can start processes.

So adding Extends Node in the class file works

answered Feb 2, 2019 by katuiche (23 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.