How to access var data from Scene1 to Scene2

Scene1 = mainMenu

Scene2 = gameLevel

mainMenu is loaded as the main scene and contains the ui and data for settings/options, how can gameLevel access those data after I change scene with:

#script of mainMenu
func _on_play_btn_pressed() → void:
get_tree().change_scene_to_file(“res://gameLevel.tscn”)

Is singleton really the correct way? I’m kinda getting the impression that singleton is not the best way for something like this

Using change_scene will completely free the current scene from memory wiping all the data that existed within it.
Using a singleton is one way to do this, you could feed it all the data from the menu into some variables just before changing the scene and then simply when the game scene loads, grab all that data from the variables in the singleton, there’s nothing wrong with that.
Another way is to use a “root” scene, instantiate your other scenes under it, and never change scenes, just remove or hide the previous scene, so that it still stays in memory, a way of achieving this is described in the documentation for changing scenes manually, it also describes pros and cons of different methods of changing scenes, highly recommend checking it out.
There isn’t really a wrong way, as long as it works.

1 Like

alright ill try the latter since im only working on a simple project

If you move from one scene to another (not include one scene into another) you can implement a Singleton or AutoLoad to pass data among any active scene