Hello. I really hope you understand my question. I figured out how to optimize my Godot game. I want to load the level in parts. The first part will be in RAM, and the second will be loaded from the script at the right time. I don’t understand Godot very well and it seems to me that my script loads the second part of the level into RAM at the beginning of the game. Please study my code and tell me if my idea will work correctly, and if not, tell me how to implement it.
extends Node3D
@export var part_2 : PackedScene #Variable that stores the second part of the level
func load_part():
#Load the second part of the level
var part_2_instance = part_2.instantiate()
add_child(part_2_instance)
This script should add the second part of the level to the scene
Sorry if there are mistakes in the text. I write using a translator
Thanks
@exporting a PackedScene will still load it in memory.
However it will not impact the performance (FPS) because it won’t be “instantiated” (i.e. “unpacked”) and put in the SceneTree (= add_child)
So if you really need to NOT load the scene in RAM at the beginning of your game, there are several options :
if you have a “tunnel” game, where each level has only a few other levels accessible, you can keep @exporting the “next levels” from each level as PackedScene, because the memory impact should be acceptable
if you have an “open world” game, where you cannot predict which level you’re gonna need, then you can try @exporting the filepath (String) instead of the PackedScene and using the load() function when you need the level. Beware, this will probably create some freeze when you call the load function. If needed you can look into background loading to smooth things out.