Instancing in another thread

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kerskuchen
:warning: Old Version Published before Godot 3 was released.


I want to background-load scenes on a grid in another thread (seamless world style). While loading the PackedResource is easy and fast, the instancing of it is not. In another thread it takes up to half a minute to instance (not even adding to the tree) which is unacceptable. Instancing it from the main scene does take around 10ms which causes a visible frame stutter at 16 fps.
Note that due to other restrictions a decrease in complexity of the scene is not an option.

Is there a possibility to background load a scene in a sane way?
If not - why does instancing a scene takes so long in another thread and what is the engine dev team gonna do about that, as this would de-facto prevent making open world type games in a sane way without resorting to parsing and reconstructing scenes from pre-instanced nodes and textfiles as those can be used just fine in another thread.

I believe this half-a-minute delay happens because, even though it instances in a thread, the engine calls resources that are accessed too on the main thread and locks maaaany, waaaay too many times, or copying PoolArrays without noticing, that kind of things, which defeats the purpose of threads (but it depends which code you run in your thread). Maybe you can open an issue on Github? Because I’d be interested as well if we could have a fix for this. Did you try in 3.0?

Zylann | 2017-09-04 09:30

Hey Zylann!
Yes I’ve tried it in 3.0. I guess making an issue on Github sounds like a good idea!

Here is the Github issue.

kerskuchen | 2017-09-04 18:33