Godot Version
4.3
Question
Currently with the way below (in singleton) i can do it,
const GAME_SESSION = preload("res://scenes/game_session.tscn")
func load_major_scene(current_scene:Node, scene_name:String, add_child_to_root:bool = false) -> Node:
var scn:Node
scn = GAME_SESSION.instantiate()
if add_child_to_root:
get_tree().root.add_child(scn)
current_scene.queue_free()
return scn
but i wanna use
get_tree().change_scene_to packed or file ("")
but in this way i dont have a way to set variables and prepare the scene.
What is the correct way?
No change_scene_to_file
is pretty destructive, you could use Singleton/Autoload/Globals to store data between scene transitions.
Introduction: Godot's scene system, while powerful and flexible, has a drawback: there is no method for storing information (e.g. a player's score or inventory) that is needed by more than one scen...
Yeah thanks, the code i shared is in a singleton class that is autoloaded. Sofrom what i understand is , the code i shared in singleton is close to good way to change major scenes (such as from menu to game session or viceversa)
Yes, though you don’t example saving any data for the next scene, your singleton will likely need a variable to keep data between the tree changes.
1 Like