So I am trying to achieve background loading using ResourceLoader but with the new single thread mode for the web.
I found this stackoverflow answer that explains how to do it using poll() each frame, however it’s from 3 years ago and the syntax and API calls are outdated: Godot : How to instantiate a scene from a list of possible scenes - Stack Overflow
Here is the relevant part:
However, the above code will stop the game while it is loading the scene. Instead do Background Loading with ResourceLoader.
First you need to call load_interactive which will give you a ResourceInteractiveLoader object:
loader = ResourceLoader.load_interactive(path)
Then you need to call poll on the loader. Until it returns ERR_FILE_EOF. In which case you can get the scene with get_resource:
if loader.poll() == ERR_FILE_EOF:
scene = loader.get_resource()
Otherwise, it means that call to poll wasn’t enough to finish loading.
The idea is to spread the calls to poll across multiple frames (e.g. by calling it from _process).
So more specifically, my question is if we can achieve that using Godot 4.3 and how. load_interactive() doesn’t seem to exist now, and if I use ResourceLoader.load there is no poll() function. Was this feature removed from the engine?
That’s interesting! But does that mean actual single thread? Or are sub threads like virtual threads? And can we do something similar to what that user does with the poll function to load a bit every frame?
I’m a begginer and the documentation is not very clear for me.
you will be sad hearing this, that godot will still run on a single thread on web. the load_threaded_request doesn’t work there from what i tested, instead just use the regular load one by one, which is slower than load threaded request strategy to take advantages of multi threads of a platform.
but can that regular load be called like the stakoverflow user does, each frame loading a little bit of the resource so the game can still run while the resource is being loaded?
you can try it, from my experience, it just couldnt run multi-thread stuffs for web. So there will be no in the background loading stuff while the game is still running perfectly smooth