Help with Progress Bar's Set Percent Function only working on 1/5 of my progress bars, and I am going insane

So I’m making a 1-4 player game (well, 1-2 co-op story mode and 1-4 player melee like in Smash Bros), and I have working parent-child class relationships for the types of characters so that everything inherits the capabilities of the parent, but has their own values for variables like health speed attack etc.

I have set up health bars on the screen with each one relating specifically to one of 4 players (and a 5th one for AI).

I have debug text to tell me everyone’s values, and can see each character controlled has their own values which are used by their damage health functions to lower it when they get hit. As such I can see characters losing health when I hit them.

I have an enum to denote which character’s health bar should be changed accordingly, and the code seems to progress through as expected.

But then the Set Percent function gets called (by whatever character I hit) and takes the current player health bar (which, when watched, shows the correct Progress Bar for that character I’m hitting) in and the correct percent amount (based on current health/max health), but then doesn’t seem to DO anything with those values. It then progresses to the rest of the code where it’s checking if current health is <= 50% of max health, it changes bar to yellow, and it current health is <= 25% of max health, it changes to yellow, but even when it hits the correct Compare nodes and gets to the Set Fill Color and Opacity nodes (even the ones set for less than 50% health or less than 25% health), it does not affect the progress bar at all.

My problem is that the progress bar for Player 2 is adjusted instantly when hit, but progress bars for players 1, 3 and 4 are not. At one point (without changing my code at all) it changed from working for Player 2 to working for Player 3 and not player 2, but testing again made it go back to Player 2. I’ve no idea what the heck it’s doing, but all the code and variables being watched shows it should be affecting the correct stuff.

See images below for proof the code thinks everything is correct. I could only upload 5 images so I did images 2-6, as image 1 is just the “before hitting” image, and thus doesn’t really show anything of importance.

Let me know if you want to see more images of my code!





TLDR: Damage is correctly being applied, the code is correctly doing the math to figure out what Percent the Progress Bar should be at (it works fine for Player 2 but not 1, 3, 4, or the AI), but no changes show up for those Progress Bars.

Can you show the part where you get the HealthBar which you plugin into UpdateHealthBarByPlayer

Sure, here’s the first 5/8:





next 3 after this.

Here’s the last 3/8:



Ok, where do you set the PlayerNumber?

Currently, each tested character each has 1 of the enums for PlayerNumber. I set their defaults, and when there’s more distinct player characters for the game, each will either have it preset or set as part of the begin play tick for that instance.

When running the code, I can see that each Update Health Bar by Player shows the correct health bar being modified by checking the watched variables, which shows P0 through P4.


As an example, the one I was attempting to attack was the one listed as Player 3 (and the code confirmed the numbers were being changed correctly), whereas the only bar that seems to correctly show the changes in the game is the one listed as Player 2. Players 1, 3 and 4 and the AI are not having their health bar being visually updated, though the numbers in the code do update accordingly.

Here are some screenshots showing the values for each of them, to confirm I didn’t somehow mess that up and have them showing the wrong Player Number for the characters being attacked:





Also, the code for all of it is in the parent character class, but only instances of the child classes are spawned and tested. Code seems to work for all of them, but only 2’s health bar visually changes while everyone’s bar’s stats (% and color) are supposedly changing during testing and attacking each character.
Here’s an image showing that I do not have ParentCharacterClass instanced in the test level.

From left to right it’s P1 (grey), P2 (purple), P3 (cyan), P4 (yellow), and P0 (red, the ‘AI’ in this case).

So,
all values update, the functions get the right values and the right health bar to work with. How did you setup your ingame widget where you display your health bars?

Initially I set up the one for Player 1, and copied that to make the other 4. I changed the names, sizes, etc for each of them to have their own names, so that I could reference them in the code. I thought maybe if the 1st one was working and the rest were not, somehow the copying of the first one made the issue for the rest, but it’s the 2nd one that works and the 1st doesn’t.


I should also note that attacking a character with Player Numbers other than 2 does not affect the health bar Progress Bars of the other Player Numbers. Attacking Player Number 2 is the only way that it affects the bar P2_HealthBar. Likewise, attacking any other character with a different Player Number enum state appears to affect their P#_HealthBar’s Percent and Color in the code, just not visually on the screen, and there’s no apparent mismatch of those values between characters.

Example, attacking the red AI character affect it’s Current Health value, and the Current Player Health Bar shows the correct value stored in it (P0_HealthBar_AI), the Percent shows the correct float value (Current Health / Max Health), and when that number gets low enough (50% or less, and later 25% or less, via the Compare Int nodes), the Set Fill Color and Opacity following those nodes gets called exactly where you’d expect it to. Just nothing appears to change in the game window for that Health Bar.

Can you share your project? I could try to debug it.

How can I best do that?

Inside UE5 go to File=> Zip Project. Then you can upload that zip to e.g. GoogleDrive

Ah okay. Was thinking there was some secret way to do that on this site, lol.

Here’s the google drive link:
(solution found, link removed)

Also I thought about maybe it’s somehow drawing multiple copies of the hud to the screen (Handle Hud is called by Begin Play tick which calls Add to Viewport for the hud, and technically each character instance has it’s own inherited version of this same code), but even if that was the case, it should change the values for all the instances of the hud (even if there’s multiple on top of each other) for each portion of the hud being changed. Also, if it were an issue with multiple on top of each other, I would assume the top-most/bottom-most (depending on how it’s drawn) would be the last one drawn in sequence, and if so, I shouldn’t be able to see Player 2’s version of it as it’s right smack dab in the middle of 5 total character instances. So, tldr; I’m thinking that can’t be it.

I’ll have a look.

No problem. All the code for the hud is found in WB_Hud (under Blueprints), and when it’s added to viewport is done in ParentCharacterClass (under Blueprints>PlayerCharacter), and Updated in the Any Damage event.

some quick controls if you want to test it:
1 - 5 on keyboard switches control of characters
WASD to move, Space to jump, LMB/RMB/E/Q are 4 attack types (punch, kick, throw, special) which (currently) are just different amounts of damage (1/2/3/4 damage, respectively).

That should be all the controls you’ll need to know to test it. Let me know if you need anything else.

Your HUDs are all overlapping. When you change this in your ParentCharacter:

it works.

1 Like

May I ask what kind of game you want to create?
Local Splitscreen or Multiplayer where everyone has his own client?

1 Like