Character widget component healthbar/Playername Replication

I have an issue replicating player name on my custom health bar. iv made a simple project using the player ID as name, each player have their own unique playerID Server=0 Client1=1.
Using print string I get Server=0 and Client=1 as expected but when I try to show my variable (PlayerID) from the player controller It doesn’t work correctly, on the server I see PlayerID=0 and I see the client with PlayerID=0. On the client side I see the server with PlayerID=1 and the client itself with PlayerID=1.
How to show correctly the PlayerID on client and server?
Here is the Link to download the sample project:
Here are some picture of the blueprints and result;

PlayerControllers only exists in server and they are replicated only to each owning client.
That means that server has all player controllers. Client 1 has player 1 player controller only. Client 2 has player 2 player controller only, etc.

All the information about the players that you want to be replicated and known to all clients you should put it on PlayerState instead of PlayerController.

PlayerState even has built-in replicated player id functionality. You do not need custom classes for that to work.

Example with your project:

Just change your character begin play to this:

Custom GameMode and PlayerController logic is not needed for it to work.

If you do not like the default unique player id in playerstate create your own as you did in your project but instead of putting it inside the PlayerController put it inside the PlayerState.

PlayerState has also built-in PlayerName. If you use that it will be set to your Steam user name if you run your game with Steam.

Hope this solves your problem!

Thanks for your reply! I have one last question, I never used player state before so how to use my custom player id in player state? Can you show me a blueprint example?

Thank you very much! Just playing around with the player state and I figured out how to do it. Now it work as it should!

I’m glad! Don’t forget to mark my answer as correct so other people in the same situation can look for the solution.

Have a nice day!