Threads and SceneTree

Godot Version

4.2

Question

I can’t do anything related to SceneTree in a Thread, for example if I try to get_children() on a node, it complains saying I should be using call_deferred() instead, but that does not return the method’s result…
I’ve seen people online mention that you need to use Mutex and Semaphore on the main thread if you want to work with anything concerning nodes, but there are no examples of that anywhere
What I’m trying to do: I have a function that takes almost a second to execute. I want to call it without making the whole game run to a halt while its processing

You only need murex if there are shared resources.

Without knowing the task, I would try to make the new thread as self contained as possible and have it emit a signal when it is finished. There is wait_for_finish but it will Block.

There is also a safety check you can disable. That may allow you to access nodes without warning. But you better make sure those nodes don’t get removed while the thread is working on them.