How to use GameState/PlayerState?

Please correct me if I am wrong.

As fas as I understand

A GameState holds infos about the state of the current game.

  • PreGame
  • Waiting for players
  • Playing
  • maybe the list of team + score
  • etc…

A PlayerState represents the current state of one player

  • Health
  • Score
  • Team it belongs to
  • etc …

In a network game who has control over the GameState/PlayerState and to who and when is it replicated?

I need to setup new Player in the login/postlogin function of my gamemode but the changes only stay on the the listenserver or only on the client .

If I am a PlayerController I can access my PlayerState to set/get variables but if the server changes a variable of my PlayerState how do I notice the change? I tried it with OnRep_* on PS variables but then I can’t find a way back to the PlayerController. There are functions in the PS to get the PC (GetPlayerControllerFromNetId or GetNetOwningPlayer()->PlayerController) but for whatever reason those are always NULL on the Client.

I don’t want to put all the information directly into my Character or PC classes if there are other classes out there that are designed to hold replicated data.

You can use custom events with reliable replication in order to allow the game mode to update the player state.

  • Here is a custom event created in the player state. I am setting a generic integer for example purposes.

In order to call that function, you just need to get the player state first.

  • Here is an example of how I store handles to the player controller and the player state into the base character, initialize the minimap system, and arbitrarily set a player number UID.

Let me know if that works out for your needs.