Passing Variables from Level Load to Level Load
Quick question, I have a player typing in their username on the main menu level. The user then stores the user name as a string variable. Then the client will load the next map, however, it doesn't retain the variable it goes back to default. I am storing the variable in the player controller, but it seems every time I load a new map it recreates the player controller. How can I pass the variable username from map to map?
asked Aug 02 '14 at 07:43 PM in Using UE4
El Death Taco
The typical way is to use a SaveGame object to serialize things like this. You'll probably need a game save/load mechanism sooner or later anyway, so this is a great opportunity to start building it.
This isn't very difficult to set up, but involves quite a few steps so you'll have to check the exact details yourself, preferably in the TappyChicken project, which has a saving and loading implemented in a fairly easy to understand manner if I remember correctly.
A rough overview: the basic steps involve creating a BP based on SaveGame, to which you add variables for the data you need to serialize. In this case it would just be a string variable holding the player's username. Then you set up your playercontroller BP so that its construction script checks for saved games and loads them, or creates a new savegame if none was found. Once the user has entered a name, you create a savegame object, write the name to the string variable and save it. With this in place, every time your playercontroller respawns on level load, it will automatically get the saved username.
Sounds complicated, but it really isn't! Check Tappy Chicken for details.
Follow this question
Once you sign in you will be able to subscribe for any updates here