0 votes

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!

in Engine by (12 points)

3 Answers

0 votes

It can be done using an autoload. Check my answer there:
https://godotengine.org/qa/24702/storing-variables-in-scene-transition-teleport-rpg?show=24721#a24721
for more details.

by (2,298 points)
0 votes

A simple (less general) solution is this:

Create a global singleton (e.g. GlobalState.gd); 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:

GlobalState.selected_character

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

by (49 points)
0 votes

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.

by (330 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.