UE5.4 PlayerState issue

Here is the situation:

I have a multiplayer lobby where each player can select their weapon and ready up to start the game.

In this screenshot the server and the client have selected the same weapon (2) printed to console every tick. The weapon is saved as an integer to the playerstate of each client. However, the issue is that; once the server travels to the gameplay level, the ‘gun’ integer in the player states are reset to 0 and everybody gets the weapon assigned to that. I’ve been plagued by this issue for ages.

I have seamless travel enabled, the player state has bReplicates enabled, the gun variable in the playerstate is also replicated. I have also made sure the PlayerState is used in both the lobby and gameplay level

Here is how the gun variable is set, this is on the lobby widget and is fired whenever you toggle ready.

Hey @IntellMove how are you?

Even with seamless travel, here’s what actually happens:

  1. Lobby Level: Your PlayerState exists with Gun = 2
  2. Server Travel Called: Engine begins loading the new level
  3. New Level Loads: A brand new PlayerState object is created
  4. Old PlayerState Destroyed: The lobby’s PlayerState is destroyed
  5. Result: Your new PlayerState has default values (Gun = 0)

This means that you need to implement some “post-travel” logic to your PlayerState blueprint.

To do that, you can override the function “CopyProperties” in your PlayerState BP and add to it something like this:


This function is called automatically by the engine, so you don’t need to do anything else.

In addition, check if you are not setting the variable value inside a BeginPlay event or a construction script; or you have initialization code in GameMode::InitNewPlayer or something like that.

Please test it and let me know if you solved the problem!

1 Like

Exactly what @BRGJuanCruzMK said or store the setting in a SaveGame slot. Have the controller read the slot and update the servers copy of the controller.

Once you start getting more settings to pass you’ll want to migrate to a Save Game and structs.

Also want to note that most games do not use a separate map as a lobby. They just use an area in the play level away from main area to handle this. Then there’s no server travel issues. Just Teleport players to the main play area on round start.

2 Likes

Thank you for the response!

I implemented the exactly line, however the ‘Gun’ int still resets to 0 upon travel. I also tried this with the variable replicated and standalone mode.

What is weird, is that when I print the gun int every tick from the player state, it returns 0 and the correct integer in an oscillating fashion.