I'll add my small contribution:
While using a singleton with public variables anyone can read and modify at any time is a working solution, I don't really like the design.
After all, the problem is to open a scene with arguments, right?
Then, this is what I did:
# scene_switcher.gd
extends Node
# Private variable
var _params = null
# Call this instead to be able to provide arguments to the next scene
func change_scene(next_scene, params=null):
_params = params
get_tree().change_scene(next_scene)
# In the newly opened scene, you can get the parameters by name
func get_param(name):
if _params != null and _params.has(name):
return _params[name]
return null
I add this in AutoLoad as SceneSwitcher, then it can be used like this:
# In the calling scene
SceneSwitcher.change_scene("map_viewer.tscn", {"location":selected_location})
# In the new scene
var current_location = SceneSwitcher.get_param("location")