Godot Version
v4.6.1.stable.official
Question
For context, I am currently making a room loading system for my 2D game. To save on performance, I am separating a tilemap into different images composed of 16x16 tile chunks, as some rooms can get quite big. Doing this in editor was expensive on filespace due to how Godot deals with resources that are not saved to files. Small rooms ended up being 2.4 MB, as opposed to about 60 KB when doing it on runtime.
I’m trying to preload rooms from adjacent rooms to lower loading screen time. I’ve gotten the chunk creation system working quite well. However, I need access to the tilemap of the room I’m trying to preload, and that means I have to load the surrounding rooms. I’m already using a ResourceLoader to create threads, but I’ve run into a problem when instantiating. I need to separate the tilemap from the rest of the scene, but using the normal instantiate() function to get access to editing the scene makes large lag spikes when loading larger rooms.
func get_tilemap() -> void:
node = ResourceLoader.load("res://scenes/rooms/" + room + ".tscn").instantiate()
var tilemap = node.get_node("Tilemap")
Is there a way to “slow down“ the instantiation function to allow it to run at a rate that will not lag the game, and allow it to be used with await? Or maybe some other solution that I can’t think of?