Hi all,
I’m learning UE’s multiplayer logic and have created a custom PlayerState to store player’s health.
The player state itself works normally, but when I try to create a UI for displaying the health, I ran into a strange issue:
For a P2P situation(i.e. play as listen server), the host player can get the player state normally, but the client player can’t.
If I change the net mode to Play As Client. All the player’s will not be able to get the proper player state.
After debugging, it seems that the player state I got is “Unknown” for same reason:
I also tried the “GetPlayerState” from the player controller, but I got the same error.
I can confirm the custom player state works because breakpoints set in C++ are triggering normally, and the health value for players are correct.
Does anyone know what’s wrong? Am I using the wrong way for getting the player state? Or Did I missed some settings somewhere?
This is probably a replication race condition, your RPC from Event Possessed is replicated too quickly, before the corresponding player state is replicated & set on the client.
Afaik for best results you should bind the event “OnPawnSet” in your player state class. This event should ensure player state and character are replicated and linked together.
For the event to be properly triggered in Standalone & Listen host, you need to bind it before begin play.
Ideal is C++ constructor if you have a C++ base.
If not, bind it from Construction Script :
Hi, Thanks for the answer.
However, I tried to bind to the event on both the character and the Widget, but I was not able to find this “OnPawnSet” event.
Can you tell me where did you have this event?
PS: I’m using UE5.2, just in case we are working with different versions