Stop from losing Game State/ Player State getting reset after Server Travel?

I’m calling Server Travel on the end of a ‘match’ and we’re going into a ‘Post Game’ Lobby. However, when I grab the game state/player states, it seems the ‘Score’ and other variables have all been reset… How can I persist it? At the very least, I’d like to keep my PlayerStates between the two levels, and could recalculate game state info from the player states.

I’ve already overloaded the CopyProperties function in my custom player state!

My two maps have different Game Modes and different controllers if that matters…

Any data that you want persisting between levels needs to be stored in the GameInstance. This post has an answer that nicely explains the difference between the GameMode, GameState and GameInstance: Whats the deferent between gamestate and game instance - Programming & Scripting - Unreal Engine Forums

In the past in my projects, I’ve had to use the GameInstance to store the scores on the server just before server travel so that I could access them in the next level and then use the server to send them to be displayed on the clients’ score screen.

Thanks for the link! I’ll try what you suggest and come back with results, hopefully in the next few days.

An easier answer than implementing all of the Game Instance saving, was just to override the Reset function in player state.

Important to note you cannot use it in the editor because seamless travel does not work in the editor. Your variable cannot be “BlueprintReadWrite”. And you also need to enable seamless travel and that only works in standalone or packaged build.

UPROPERTY(BlueprintReadOnly, Replicated, Category = "Preplan")
Test = "Original Value";  



void AShooterPlayerState::CopyProperties(class APlayerState* PlayerState)
{
	 Super::CopyProperties(PlayerState);

	 if (IsValid(PlayerState))
	 {
		this->Test = "New Value";
		
		 AShooterPlayerState* ShooterPlayerState = Cast<AShooterPlayerState>(PlayerState);        
		 if (ShooterPlayerState)
		 {            
			 ShooterPlayerState->Test = this->Test;            
		 }
	 }
}
1 Like