Client side PlayerController has no PlayerState...

As per title, I’ve been implementing a simple UI to show the scores for each player in a MP game.

In doing that, I noticed that the HUD’s owning PlayerController always has a nullptr for PlayerState on all clients, the server has a valid pointer.

As such, I can’t seem to get hold of the score reliably from the playerstate for the client side HUD :frowning:

I *can *get the controlled Pawn from the PlayerController, and that does have a valid pointer to the PlayerState on both client and server, but obviously I’d like the score to persist as the player is respawned etc…

This is using UE 4.25.4. I did something similar ages ago in 4.23.1 (an asteroids clone) and that does have a valid playerstate in the playercontroller, just checked.

Has there been some structural change re: PlayerStates in 4.25.4… I’ve searched the forums but haven’t been able to find anything that appears relevant.

I may be missing the obvious here, shouldn’t a PlayerController always have a valid PlayerState pointer?

There’s no garauntee the pointer will be valid at anytime, because it’s a different actor and that actor takes time to replicate. For MP games you have to design the code to be resilient to that and handle it gracefully. For UI, the easiest/best approach is just to tick the whole thing usually.

For a scoreboard, you’re best off getting the player states from AGameStateBase::PlayerArray - since it contains all active players in the current game. Again though, some of those entries may be nullptr at times.

Doesn’t seem to be time related, the pointer never becomes valid regardless of how long I leave it.

When the server updates the score in the playerstate, it’s OnRep_Score() is called on all clients, but the PlayerControllers OnRep_PlayerState is never called.

The PlayerState should become valid at some point early on.

As for replication, that’s behaviour is correct. OnRep_PlayerState() will only be called when the controllers’ PlayerState variable changes - not when the internal properties of the PlayerState change.

Sadly it does not become valid, at any point.

I set up a small empty project as a test and on that it does, pretty much instantly as expected, so I must be buggering something up along the way.

Time to start taking stuff out again :wink:

Thanks for responses.