How to get a reference to Player State?


So I am working on the lobby map for our game and I made a system for checking if all players are ready to start the game, but it was bugged. My new idea is to place the variable “PlayerIsReady” inside the player state, since that can be accessed both from the client and the server(as far as I understand). But I can´t find any working object reference when casting to the BP_PlayerState. Anyone that has a good grasp on these things?


You can get the PlayerState from the PlayerController.

Be aware that the Client can only “read” the variables on PlayerStates and will not be able to send a RunOnServer RPC to the server from within the PlayerState since the clients don’t own any PlayerStates.

Each Client own one PlayerController though so you can make the RunOnServer RPC on the PlayerController and once it reaches the Server the Server can set the variable on the PlayerState and if it is replicated all the clients will eventually get the update.

Thanks Garner!

So I got it the casting to work now by with your help. I cast from the Trigger BP to the LobbyplayerController and get the PlayerState and then cast that to my Player State and set the bol “isReady” to true. Might it work to forgo the player state and just place the bol inside the player controller?

No, if the goal is for everyone to see the “isReady” bool and not only the server then it has to be on PlayerState or something else that all the Clients have.

Clients only have their own PlayerController so if you try to read “isReady” from a PlayerController that isn’t your own on the client then you will get a null reference.