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.
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
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!