Is it possible to use threaded chunkloading to load simple metroidvania-like rooms?

Godot Version

4.4.stable

Question

I’ve been wanting to make a metroidvania for a while, but I really wanted to try and make the rooms load into each other seamlessly, so I thought maybe chunk loading would make this possible somehow.

What I was thinking was each room would be a separate scene with a tileset, background, enemies and such… named room_0_0.tscn or room_15_129.tscn, etc. and whenever the player is within range or close to that room, and the room isn’t loaded already it would load it by using something like load("res://room/room_"+str(room_position.x)+"_"+str(room_position.y)+".tscn")

and anywhere there’s a room I haven’t created for that coordinates it would just load a wall of solid tiles or just a blank wall or something. The rooms would not need any randomness or anything. They’d just be rooms I would build myself in editor. I am also aware that its bad to use load over preload but I’m not exactly sure how else I could do something like this because you can’t really put strings into preloads from what I understand.

I was using this guide to try and extract something from the idea of chunk loading, but understanding it is somewhat confusing and although I feel like I’ve gotten close to understanding it I’m still a bit lost. Any amount of help would be appreciated.

It is certainly possible. However, Godot has a rather sizeable issue with object instantiation, even in threads. The add_child() function is inherently single-threaded (it exists only on the game’s main thread), so there is no way to guarantee that your chunk loading won’t cause stutters and sputters.

Loading data is no problem, and that can readily be done in threads to eliminate any kind of glitches in performance. However, no matter what you do, you will have to use add_child() to add your dynamically loaded room chunk to the scene tree. At that point, your game may stutter.

In my own games with threaded background loading, I frequently see no noticeable glitches when adding scenes to the scene tree, so relatively small objects can be instantiated smoothly. But some scenes will still cause small, noticeable stalls. If you can limit your dynamic loading to times where the user won’t notice or care about the stalls, then you can definitely have a chunk-based game.

1 Like