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?

,

Thanks for the quick reply! This is actually why I am trying to get the user name. This is a multi-player game where I will need to save their location, inventory, ect. And I was going to use the username they entered as the save file name. I am currently saving values but it applies to all the clients logged into that server. Pretty much I want a save file for each player, or is there a better way to achieve this?

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.

Ah, I don’t know much about multiplayer stuff, but for that I presume you would rather use something like a subclass of PlayerState to store and replicate that type of data in a secure way.