Two HP bars working differently

Hello everyone,
First time posting here, be kind as i’m still learning the ropes.

I’m tryin to make a two player game, i have experience in programming just not in Unreal so it may be a novice problem.

I have created a Healthbar for my UI. and i’ve added it as a component on my character blueprint.
Implemented a bullet and a blueprint that runs serverside to apply damage. (Working as a Server Listener)
When i shoot, and hit the other character their HP go down correctly and the bar renders the damage fine.

I’ve then tried to implement in the “Begin Event” blueprint, the addition of the HP widget so that it could be locked unto the screen and not floating above the head of my characters.

So far i got this:

Problem is, the bar in the HUD gets damage everytime i deal damage ( to myself or to the other character) and it only lowers on the player’s screen. so if i Hit player 2.
I get the following:

Hud on player 1 shows hp diminshing.
Hud on player 2 is still
Hud on player 1 head is still
Hud on player 2 head show hp diminishing.

This also happens backward when i shoot from player 2 to player 1.

It gets me really confused since it all works great, until i try to add the component via Blueprint.

Anyone has a clue of why does this happen?

I’ll link other parts of the Blueprint just to get you the full part of it:

This is the trigger for the damage on the “missile”

this is the logic that applies the damage:

You can save the Widget ReturnValue and use that as a Ref rather than GetWidget->Cast

other than that you Damage Events look fine so likely you’re not updating the widget properly

I’ve adjusted the blueprint as suggested and thank you for that it is now more readable.

I think as you just said, the problem lies somewhere the widget update, because if i write a log where i indicate the amount of hp i have, they’re getting subtracted correctly.

Player 1 gets damaged when he’s hit, and player 2 does the same, the bars are just linked wrongly to the proper character.

I’ve made another bar as a “timer”, and made a pickup that replenishes the bar.
If i get it on the first player, it replenished the bar on the second player, but the value itself is correctly adjusted to player 1.

Since the problem seems to be an unalignment of HUD to the proper player, has anybody a way to fix this?

Wanted to add, because might be part of the problem.
The blueprint is part of the Character Blueprint, and i’m using the same Character Blueprint for every player.

At this moment i still havent’ found a solution, still looking around.

i’d need to see your widget logic, but to get you started the correct way to update it is,

  1. Make your Health variable RepNotify
  2. In the OnRep function call an EventDispatcher (lets say HealthUpdated)
  3. In your widget Construct Event use the OwningCharacter variable you’ve set (Cast if needed) and Bind to the HealthUpdated Event
  4. On you newly created Event handle the health update

Here, i’m posting More of my Blueprint.

I’ve tried doing what you suggested, and at the moment when the first character attacks, is lowers the hp bar from both the player as players 2 attacks don’t move any bar.

Yet, the values are correctly influenced by the hits since i’m logging the HP and it pops out as the expected Value.

This (now unlinked) was the blueprint of Percent to get the values of HP:

(post deleted by author)

I’m sorry for the many messages, being a new user doesn’t let me paste several screenshots at once

The Creation of the UI at Beginplay:

The Blueprint that adds damage

As for your suggestion, this is what i made:

Made the Event Dispatcher and into the progress bar i made this:

I have another bar that depletes overtime, and when i pickup an item it recharges, but it does so in a wrong way ( for the UI ) since the Light effect that Pops when the bar is full, is actually working as intended, even if the bar is empty.

Whatever the problem seems to be a common one in my implementations

getting there, So you dont need the Cast, that was just in case you used a base class, and you dont need SetOwningPlayer which youre currently setting to Null

otherwise it mostly looks ok, so whats the problem?

With the blueprints i’ve shared the situation at the moment is this:

Player 1, can Attack player 2.
Both The HP bar from player 1 and player 2 Depletes.
But only the Variable Health of player 2 decreases.

Player 2 can attack player 1.
Both bars aren’t affected.
But the Variable Health of player 1 decreases correctly

is the missle spawned by the server? if not it fail the Authoity check and not apply damage

The missle is correctly spawned from the server.

If i put a logString into the logic that deals damage, i get the correcting decreasing values, so player 1 hits and correctly damages player 2.

I have an issue with the Healtbar values, because the Healbar doesnt’ correctly recognize the value of the player, and instead reports a faulty one.
Player’s 1 hp is linked to the value for Player 2 and the like.
So i think the problem is in how i spawn the UI during the Beginplay event, but i can’t wrap my head around it

this is all inside a Character yeah?

widgets should only be spawned on local players (begin play runs for both server and players) so you can use an IsLocallyControlled check but i dont think thats the issue

also whats the delay for on BeginPlay? this is always a bad idea

otherwise ill have to check this with fresh eyes tomorrow

Yeah, all the script except the “percent” function is from the Character blueprint, i was already seeing around that it’s not a good way to make this work and i’ve been looking for a different implementation.

I’m working on it, will post soon if it has worked, because it may be just a bad idea to make things work in the way i’ve tried.

Since the forum doesn’t let me post it now but seems to rememer i’ll add things to this post tomorrow aswell.

i Just did it,
I completely razed the model i made and did it again, i swapped “applyDamage” that was a custom event with a default AnyDamage one for damage.

It wasn’t it tough.

I’ve made the variable Health on rep, developed on the function and made the event dispatcher.

I was probably doing something wrong because the way you told me to do it, actually worked the second time.

Also, i changed the BeginEvent logic that now starts on “OnPossess”, also i focuses all the HUD in a single HUD blueprint so that i have only do add that to the Viewport.

Now the Health is working fine, the timer too and the repleneshipment of the values acts accordingly.

Thank you for your support and patience.

I’ll probably be writing soon since i’m going to have a lot of free time under christmas so, in case you’re not gonna be the same angel twice, Happy Christmas to you and your dears.

To the next time!

1 Like

congrats on getting it to work