Multiplayer Health Bar Replication Issue

Hello all, multiple days on this. Thanks in advance for your help. Novice on replicated variables and trying to wrap my head around it. I will try to be clear, concise, and cogent.

I am attempting to implement a replicated healthbar in my multiplayer game so you can see how much health other players have.

I have followed this YouTube tutorial FWIW: Unreal Engine 4 Multiplayer (replicated) Health Bar Tutorial | UE4 Replicated Health Widget - YouTube

The good: I get the server updates and the client updates expected from within the widget blueprint I am attempting to update.

Image 006

It even prints with the proper values I expect.

The bad: My player HUD healthbar [BP_UW_Health] does not update on either the client (1) or server (0). The variables passed from the Character BP, both CurrentHealth and MaxHealth float variables are replicated.

Here is the variable flow from the lander to the healthbar blueprint into game.

Initialize the healthbar play hud in the Character_BP:

From within the Character BP Calculate health and update replicated variables on the server:

Image 007

Get those server variables and update Character_BP variables, then trigger a custom UpdateHealth event that updates the required values in my healthbar user widget.

My Character_BP has a reference to the BP_UW_Health health bar UI widget in order to refence those variables.

Image 009

I attempt to update the healthbar percent in the BP_UW_Health widget and I thing this is where things go sideways.

According to the PrintString, I am receiving the correct values but they are not updating the progress bar percent as expected. Bar stays at 100%.

My health bar widget is in my Character_BP stack and displays correctly in the game, but the progress bar is not updating. HELP!

(Thanks again in advance!)

The easiest way to think of this is how ownership works. Replicating to a client means it replicates to the “Owning” client. Usually the owning client of a pawn or character is the player that has control over the pawn or character. To properly update the health bar for all clients you need to use a MULTICAST replication event. The multicast should be called on the server. You can pass the variable from the server to all of the clients through the input of the multicast. Basically, replace your client event with a multicast. Keep in mind, because the widget is not replicated, each client has their own version of this widget. Which is why we need to run an event on all clients through a multicast.

This is a wonderful resource to learn replication:

Thank you for the response! And that resource, after a quick scan, looks excellent. I will dive into this. It’s a goal to truly LEARN, not copy-paste my way to a game. Thanks.

For this particular case, being a novice, I don’t know if you meant the event BP_UW_Updatehealth in BP_UW_Health widget that is referenced in the Character BP, the UpdateHealthServer event in the Character_BP that runs on the server, or the UpdateHealth event referenced in the Character_BP that runs on the owning client (and calls BP_UW_Update_Health in the BP_UW_Health widget BP.

Regardless - changing these 1 by 1 to Multicast did not resolve the issue.

I do appreciate the response and the resource.

Only your “UpdateHealth” that you have set to run on owning client needs to be set to multicast. The rest will stay the same

1 Like

Thank you. Now a log full of this. I’ll dig a bit.

Blueprint Runtime Error: "Accessed None trying to read property BP_UW_Health". Node: BP UW Update Health Graph: EventGraph Function: Execute Ubergraph Lander Six DOF Blueprint: Lander_SixDOF

Seems like I’m making a simple mistake. Server and clients do report proper damage values in the BP_UW_Health progress bar blueprint.

Do the variables have to be named the same? I named them differently because I wanted it to be clear where that value resided. Figured I was just passing a number so it shouldn’t make a difference? But maybe that breaks replication of the variable?

Image 014

Even in this case, I am still getting the proper values on both client and server.

All the clients and the server reporting the damage % from within the widget BP and printing on the screen with proper value:

Got it WORKING!

Ok, as a novice I am sure I am doing things all kinds of wrong, BUT it works. I’ll continue to dig into replication and learn best practices. This is what I did:

  1. NOT using my UpdateHealthServer event on the server
  2. NOT using my UpdateHealth event on the owning client or as multicast.
  3. NOT using a reference to the BP_UW_Health widget blueprint in my Character_BP

I had a name over my character in the game that was working fine. I looked at the function to display the player name of other players. I noted the player name was coming from the Player State and therefore replicated.

I applied this logic to my health bar. My Current Health and my Max Health variables needed for my progress percent in the BP_UW_Health' widget are replicated. On tick, I call this function in the Character_BP` (using Character_BP as a generic term) and the replicated variables properly update the healthbar on all clients.

Image 017

Woot!

Let me know how this is all kinds of messed up and I will refactor, but it works!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.