-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Hi there,
I'd like to request a feature since I have been having a great time using this addon for my project.
Passing data between scenes is useful when you want persistent data between scenes without using a global script. In my case, I am creating a multiplayer game and each player obtains information(data) about their lobby. Which is then passed to the next scene as the transition happens. This data is used to initialize other parts of that "next scene", and then never used again.
It's not that pretty but, I have done the following to pass data between the scenes and thought you might know a cleaner way to implement it.
- Modified all methods that call
_change_sceneto accept a Dictionary as a parameter. (Defaults to an empty Dictionary) - Ensure any scene that I wanted to pass data to has a variable called
Msgas a Dictionary - Set the message for the new scene after the old scene has been freed
My Project
# my_main_scene.gd
# Lobby Data as a Dictionary
var Msg: Dictionary = {}
# Change to the new scene after it is done loading
func _OnLoadingFinished() -> void:
SceneManager.change_scene_to_loaded_scene(
FadeOutOptions,
FadeInOptions,
GeneralOptions,
{Msg}
)
passScene Manager Addon
# scene_manager.gd
# checks different states of the scene and makes actual transitions happen
func _change_scene(scene, add_to_back: bool, Msg: Dictionary = {}) -> bool:
#...
get_tree().get_current_scene().free()
# Pass the message to the current scene if the scene has a "Msg" variable
if "Msg" in scene_instance and not Msg.is_empty():
scene_instance.Msg = Msg
root.add_child(scene_instance)
#...
passReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels