How to load on a player based on other scene selection?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By santiagomatta

Hi all, I am having a problem here. I am programming a mini game in wich you should be able to choose a character in the main menu and when you click on play, the game scenes loads the selected player. I have no idea how to keep and transfer that data from one scene to another! Thanks in advanced!

:bust_in_silhouette: Reply From: hilfazer

It can be done using an autoload. Check my answer there:
for more details.

:bust_in_silhouette: Reply From: ConnyOnny

A simple (less general) solution is this:

Create a global singleton (e.g.; could look something like this:

extends Node

var selected_character = 0
var selected_difficulity = 0
# other global config stuff if you like

Then in the menu controls do stuff like when the user taps “ui_right”:

GlobalState.selected_character += 1

For the preview in the menu and for loading in-game you can just read the selected character like this:


Also don’t forget to register your global singleton as such in the project settings.

:bust_in_silhouette: Reply From: Sprowk

In bigger projects it is usually better to have parent node which manages data transfer. In this case as others pointed out is easier to use singleton because you don’t need such a great control.