[Multiplayer] How to save player stats between levels

Hello everyone!

Im doing a multiplayer project and have some problems:

  1. How to properly save player stats when traveling between different levels?
    1. Health, stamina, experience, etc…;
    2. Inventory items array;
  2. Where and when i need update player stats?
    1. On value change?
    2. When i use Server Travel command?
  3. How to properly test multiplayer replication?
    1. Do i need to create session every time i want to do a playtest?
    2. Standalone?

My current game loop:

  1. When game starts, every player spawns in Level_Shop, where they can buy items and choose next map;
  2. After choosing map, i use servertravel command to load new level with some goals on it;
  3. After completing the goals, i once again use servertravel command to move back to Level_Shop
  4. Repeat.

If you can provide some examples, i will appreciate that!

I tried to work with Player State Class, but it didn’t work for me or im using it incorrectly.

For multiplayer servertravel you should enable Use Seamless Travel which can be found inside your GameMode.

Seamless Travel will make your clients load the map in the background. Once loaded, they will travel there.

On the one hand, it provides a smoother experience, but on the other, it is essential for transferring state from one map to another.

Seamless Travel will keep your clients connected, unlike hard travels.

  1. To transfer data between maps you can use the Copy Propertiesevent in your Player State.

This event gets called when a SeamlessTravel is detected before destroying the old Player State and after the New Player State was created, therefore you can use the “New Player State” to copy data over to it.
For instance you grab the current health and save it inside the “New Player State”

  1. I don’t fully understand what you mean by “when to update player stats”, are you referring to when to update the Healthbar in the UI ?
    If so, only update when it’s value changes (inside the OnRep_…)
    There is no reason to do that with ServerTravel together as when you copy your properties onto the “New Player State” it will get replicated and call the corresponding OnRep_… functions which should broadcast your changes.

  2. You can test in PIE by playing with multiple clients

Consider using Network Emulation to simulate a real-life scenario with package loss and latency

This alone should cover a lot of testing area, but it is always worth packaging your game and testing it together with a friend or a second computer.

Thx for answering!

But for some reason it doesnt work:( Values from Player State reset\\doesn’t save for some reason. Event Copy Properties doens’t even work.

This is my code in Player State:

In Player Character Blueprint, i try to get updated values from Player State on Possessed Event:

I use Seamless Travel Flag in Game Mode:

And my Game Mode use valid Player State asset to save variables:

Using “GetPlayerState[0]” is generally a bad idea in multiplayer context.

Get the player state from the controller instead.

Also place a breakpoint in Copy Properties to see if your values are correct. Make sure the “New Player State” is BP_GameCore_PS and if Health, InventoryItems, etc have the correct data.