[Multiplayer] How to Save Player Variables such as playerName and playerScore inbetween maps via server travel

Hi all,
I am currently teaching myself multiplayer logic and have run into a problem that hasn’t quite been answered in the forums anywhere. I simply would like to store variables via blueprint logic across different levels when servertravel/ is called. For example, in the lobby level where players connect initially, they have the option to set their name(text variable in the player state).

When servertravel/ is called I am aware that player controllers and player states are destroyed, so what is the proper method to keep variables and to re load them to each player state after a servertravel/?

I have tried setting the variables in the Game Instance which I know does persist, however after servertravel/ all clients receive the same variables from the instance(for example everyone gets renamed ‘steve’). I have also tried using a save game to slot method but I am not sure how save game to slot even works in multiplayer, as I can only seem to create a single save file that only one client can access, the rest return a ‘none’ error.

Another example would be pointsEarned(float variable in the player state) that each player earned during the level, and then saving them while after another servertravel/ back to the lobby map so they can be reloaded to the proper player state.

Any help via blueprint screenshots would be most useful as I think this is a problem many developers will run into.

1 Like

I struggled a lot with this too, but in the end I ended up storing all the player variables I wanted to transfer in a “PlayerInfo” struct in the Player Controller, keeping that struct updated in the Game Mode and putting each players struct in a Map where the keys are strings with player names.

When its time to server travel I store that map in the Game Instance which is persistant across maps, then read it on the other side linking each player to their PlayerInfo struct using their name.

Edit: here are some pictures from my blueprints (sorry if a bit messy)

Update each players struct in the Game Mode BP every time you make a change

Then go through the Player Controller to access the game instance and store the Map variable

In the Game Instance

Then after you server travel

Get the map variable in the Game State BP

and finally from there, you should be able to access the Map variable with with the new Player Controllers

It should be noted I use the Advanced Sessions Plugin for steam to get player names and in shipped products its probably better to use uniqueID strings instead.
Hope this helps!

1 Like

A great work around, thanks many times over :slight_smile:

Late to the party, but just wanted to drop the Persistent Data Compendium here.

2 Likes

Thanks a bunch! This really helped me out moving from my lobby to the game arena.