Using Player State

I’m working on a multiplayer project. I read that variables such as health, mana, and so on, should be kept in the Player State. For example, I created a variable “Health” in the Player State and I need to perform some operation on it in the Player Controller, how can I do this without using C++?
I tried cast to Player State from Player Controller, but the editor of an error.

Player State is for information about a player that you want to keep even when your player dies or disconnects, for example, level, maybe weapons, score, deaths, wins, playername, etc. I wouldn’t put health or mana in the playerState since those aren’t really persistent values in most games, but maybe in your game you want to have a health history or something, so that’s your call.

As for using the player state you don’t cast to Player State from Player Controller, the Player Controller already has a reference to the Player State you just type Get Player State in the search box and that variable should pop up, you do need to cast it to your own player state class though.

When i use reference to the Player State, the editor gives the following error: Accessed None trying to read property PlayerState from function: ‘ExecuteUbergraph_ThirdPersonCharacter’ from node: Print String in graph: EventGraph in object: ThirdPersonCharacter with description: Accessed None trying to read property PlayerState

This picture contains example of use Player State with default variable:


When i try find my custom variable in the search box:


For the first picture, wait at least half a second before using a replicated variable, sometimes the first replication hasn’t arrived yet when the first tick happens.

The problem in the second image is that you are not casting to your custom Player State Class. You need to cast it.