HUD progress bar stays at 0

It works fine for my player health and weapon energy, however, for my turret’s weapon energy (drains at every shot), the progress bar remains at 0. and I think i did everything right. Can you help me?

285173-gfg3.jpg

While I don’t technically see a problem with this working from the screenshots provided, I think we’d need more to be sure. What does energy start default to? Did you confirm the value is high during the game? Does it decrement properly in code but just not visually work?

It may be easier to use normal numbers (like 1-100) for your energy levels, and then simply use a “Normalize to Range” node to get your 0-1 percentage value, but that’s semi-unrelated.

The float is a default of 1,0. When i remove the minus-float, the energy bar stays the same → black. There are no other references attached to it. In Widget Designer, the “percent”-value is 0,5… that’s about all i know.

Are you sure that the “cast to HelpTorus” is successful? If that fails the percent will never be read properly. Is this the same way you setup the other bars?

If that is all correct, my suggestion would be to start looking at the widget attributes to ensure it’s working. Try setting that bar to use the same code as another bar and see if it works normally.

I bound the player’s health to this bar and that works. They’re made of the same scheme as the other bars: duplicated and rewritten for the appropriate float…

The CastTo is fine. The HelpTorus is a child actor of my FirstPersonCharacter… could this make it quirky?

In that case it really seems like your float is 0. When you print a string with the value of the float on the percentage function, what does it output?

It does print 1.0 for the float and “0.0” when I link the progress bar to the string.

Bump… still didn’t fix it… could it be that the progress bar won’t read the values of child actors? Or do I have to use CastTo differently?

If it prints 0.0 when you add a Print String node to the percent, it seems like it’s failing to cast properly. It should cast to child actors just fine. Drag off the “Cast Failed” and have it Print a string and see if you see it in the logs. You can also add a debug point and just watch to see if it fails. Maybe put another return node on there for the failed path that just returns .5.

Wow, it really does…
What now?

285274-failed.png

(250 is a walk speed)

So now I’d drag off the player character node and hook it up to that Print String to see what class it is coming in as, and then ensure that you have your parent/child setup properly

Character node - which one and where?

Sorry, your “Get player character” node, hook that up to the Print String you added on the failed route so that you can see what class it is.

It says FirstPersonCharacter

Right, so your character in the game you are trying to read the Energy from isn’t being used. In your GameMode, ensure you’ve selected your HelpTorus child class as the character you want to play as.

Oh these HelpToruses are additional auto-turrets above the player, I don’t really want to play them (they automatically fire). Do you think I have to set their energy variables in my FirstPersonCharacter? Trying this for a second.

In that case, you will need to get a reference to that Torus. You can do this in your FirstPersonCharacter, setting a variable so that the Player always has a reference to the Torus.

In your Percent function you can then

  • use the Get player character node
  • cast to the FirstPersonCharacter
  • get your Torus variable
  • get the energy

The other option is, as you said, to simply store the energy on the player (and change your Cast to the FirstPersonCharacter), and then make your Torus change the Energy value on your player.

Forgot to say that the 2 Toruses have their separate Blueprints where they spawn projectiles which might be a bit too much work for this simple thing!

Would be simpler to keep the energy drainage in their Blueprints.

Shouldn’t I change a tiny connection in the progress bar nodes? Get the Child Actor somehow?

And, do you think this answer is on topic? → Child actor component: cast failed - Programming & Scripting - Unreal Engine Forums

Where are you setting the percent of that bar at?

If your Torus classes are being attached as children to the first person character, that answer would work. You can use

  • Get Player Character
  • Get Child Actors
  • Get ( 0 ) “a copy”
  • Cast to HelpTorus
  • Get Energy

But this will only return the first Child actor. This is also not the most efficient method as that is fairly heavy for just reading the energy variable constantly.