Instantiate() freezing game

Godot Version 4.3 beta 2

Question

I load my scene with ResourceLoader.load_threaded_request.
when status == ResourceLoader.THREAD_LOAD_LOADED

ResourceLoader.load_threaded_get(_loading_scene).instantiate()

I get my scene with .instantiate but when I do .instantiate my game freezes, I don’t want my game to freeze I want it to load in the background.

I tried doing intantiate in the thread so that my game doesn’t freeze, but the main thread still freezes.
my_thread.start(_add_loaded_scene);

This freezing my game:

func _add_loaded_scene() -> void:
	print("Instantiating")
	var _scene_inst:Node = ResourceLoader.load_threaded_get(_loading_scene).instantiate();
	print("Complete")

This doesn’t freeze my game:

func _add_loaded_scene() -> void:
	print("Instantiating")
	while 1:
       print("thread")
	print("Complete")

freeze as in freeze forever or just a few seconds?
if for a few seconds, it cant be avoided for now, even with sub thread.

just a few seconds

cant be avoided for now, especially you are loading a big scene
so it’s best to load all scene and cache it/store it into a variable, then the next scene that tries to load it will just load it from that, so no freezing for a few seconds every time you need the scene. Just the very first time you need to load the scenes, it will freezing

1 Like

Thanks for your help!

1 Like

may have a look on this, i’ve done similar but basically you want to list all the scenes file you wanted to load, then load it and store it into variable(s)
just make sure you load it all into a scene that wont be queue_free’d

1 Like

The problem for me was the CSG meshes in the scene. I put about 5000 csg meshes for testing and it was freezing, but when I changed them to normal cube meshes, it started to freeze.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.