How to get other player's hp bars to change color?

I have a multiplayer game in which I need my character to change other players health bars to red if they’re on the opposing team. I’ve been struggling for a while to get this and the best I have ever achieved is to get it to work on the server player. No matter what I try the client never works. The player controllers hold which team they’re on and I know that they don’t exist on the client so i’ve tried to have a RPC that runs on the server that gets the owner and passes it to the client with another RPC but that doesn’t seem to work either. Any help would be greatly appreciated.

Some approaches that can help you:

  • You can ask the server wich team you are when your character is spawned, or Player State. It will depend on how your match is initialized.
  • You can have a replicated variable under the player state, set it to OnRep and inside the function created, change the color based on the resulting value of the variable. (Easier and more straighforward approach)
  • You can use your game mode (Server) to set the team under each player controller when match starts, overriding some methods in GameMode class (not GameModeBase!)
  • You can have a replicated class of a team (TeamActor) that stores the players, have some internal important information, spawn them and have Game State(clients will have access, too, if the references are replicated) have access to this. After that, you would think on how to Manage the teams (which class would contain the logic)

Personally I prefer the last one, which is almost how UT does.

The question of which team I’m on doesn’t need to be answered. I can gather that information from the server. The problem is that the clients can’t. For each player character in the game, I need to set each OTHER players overhead hp bar color. This is on a per-client basis.

Currently my setup is thus:
Inside the game mode, i wait until all characters are spawned, then call a RPC to client called Colors to which I pass my existing player controllers. Colors is an event that exists in my game state class.
The Colors RPC loops through the controllers calling the Client Manage Hp Bar Colors RPC that is multicast(the only way I can get it to work at all). That RPC simply calls a function inside my Third Person Character class called Manage HP Bar Color.
Inside Manage HP Bar Color I have tried numerous ways to have each client get each other clients team, but to no avail. I created a variable inside player state that i set on possession. I use a RPC to client for that but my logging shows that it only appears to function on the server, which makes no sense to me. I would attach a screenshot but I know that I’m not doing it right and that there’s clearly a fundamental that I’m missing or misunderstanding.

I agree with Gbr. You should have a replicated color variable that is set by the server. You can then bind your health bar color to that variable.

I’m having a hard time visualizing what I’d be doing here. Could you provide a simple example? From what I understand, I would have a server RPC in my third person character class that does the team comparisons for health bars and sets a replicating color variable on the server which which I will set my widget’s color to on the client? That will allow each client to modify each other client’s hp bar?

You’d want an event or function that is authority guarded (on switch authority) inside your character blueprint (or wherever your color variable is) that sets the value of the color variable. Said event or function would be called from your gamestate class, passing the color value as a parameter.

Then inside your healthbar UMG class, you would cast to and store a reference to the class that contains the color variable on construct. This will allow you to bind the color of the healthbar to the color variable.

I did this so simply:
In multiplayer, you must set TEAM. it is used for damage and for hp bar color.
all widgets exist only on your PC. in your widget BP, get your team tag and compare it with tag of enemy from where you getting HP information. if tags are identical -> set hp bar to blue, if not, set to red… simple as that.