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: https://drive.google.com/open?id=10Rz32dsaqiUGnYTXJiNKWHLFMTOVueNw Here are some picture of the blueprints and result;
asked Aug 01 '18 at 02:40 AM in Blueprint Scripting
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!
Follow this question
Once you sign in you will be able to subscribe for any updates here