HI! . I read some UE4 Q&A and I just found out there are something call Player State. I understand what it use for, and it sounds like it is not inside the Player Controller Blueprint and is not inside a Character Blueprint. Can you tell me how to create Player State, where to find it and how to set it up please?
Once you have created a custom GameMode blueprint, you will find the PlayerStateClass setting in the Class Defaults of your GameMode.
Thanks! So in game mode I can only choose 1 player state and I want to store Health variable for many characters, is that mean I have to create Health variable for each characters, health1, health2, health3… something like that?
And also for Widget Blueprint, when I create “cast to playerstate”, what is the object reference? I couldn’t find one that works for it.
I’m blissfully ignorant about all things related to multiplayer, so I don’t have any suggestions. Pretty sure someone else can step up and give you some useful pointers!
No each player will have their own playerstate. If you are using playerstate to handle health you’ll want to make sure you reset that health variable when the player respawns because playerstate is persistent even if the player character is destroyed/respawned. Some people like to use the player class to store health.
To get a reference to player state from your widget you’ll want to get player controller and get the playerstate object from player controller. Then cast to player state.
Did you mean APlayerController or UPlayer? And i assume you mean the APlayerController that is on the server and not the local APlayerController instance.
Pretty sure it’s neither. Instead it’s player state. Reading in context. Player state is persistent. So it’s a good place to store health for multiplayer.
This was interesting:
I believe you can also get player state by- getting game state > player array> get (index) >> and cast from there to player state. Check this out. http://www.nafonso.com