This strongly depends on what the biome scene is supposed to do: is it only a graphical + collision node? does it need to "remember" player modifications (eg: an open chest need to be open when the player come back to the scene later)? does it make frame by frame calculation that need to continue even when scene is switched, or is it ok to freeze everything when on another scene?
The easier way to do it is to simply have 1 biome loaded at a time, which means queue_free() the existing and load a new one when switching.
func switch():
get_child(0).queue_free()
var new_biome=load(folder_path_to_scene_biome).instance()
add_child(new_biome)
change_scene()
and change_scene_to()
does the above in a single method
in case you need to recover the previous state, you can either save the "modifications" on a set of variable (maybe a resource or dictionary) and then recover then and apply them to the newly added biome.
Or you could set aside the unused biome with a simple biome.hide()
(collision and script will still work).
In case you want to stop everything in the unused biome, you can implement a scripted functions to make everything stop working when not needed
func switch()
$SandBiome.stop_activity()
$ForestBiome.recover()
func stop_activity(): #it will obviously be much more complex than this
set_process(false)
$CollisionPoligon2d.disabled=true
hide()
Or, you can remove unsused biomes from the tree with remove_child()
and store the node in a variable. This probably looks easier than it actually will be, because it is true it will automatically store every modification and recover it later, but the orphan child nodes needs special attention, because every connection with external nodes will be broken, therefore you might end up with a lot of errors.
So you again need to implement some sort of "stop" function
var biome1
var biome2
var current_biome=null
func _ready():
biome1=load(path_to_biome1).instance()
biome1.stop_activity()
biome2=load(path_to_biome2).instance()
biome2.stop_activity()
switch(biome1)
func switch(biome_to_switch):
if current_biome!=null:
remove_child(current_biome)
current_biome.stop_activity()
add_child(biome_to_switch)
current_biome=biome_to_switch
current_biome.recover()
i know this is VERY generic, but i hope you could get some inspiration
in the docs they cover this topic here:
https://docs.godotengine.org/en/stable/tutorials/misc/change_scenes_manually.html mostly they give the same advices, maybe with a little more examples and explanation on memory usage