Gradually charging progress bar

I’ve been looking around for examples of progress bars that gradually charges whenever a player takes a damage or uses up available energy. I couldn’t find anything or examples to learn from. I was wondering if anyone here had any examples they can share. Better yet, if you have some ideas on how to make the progress bar charge every few seconds, I would be interested in learning how you put it together.

You can do it pretty much the same way you would a stamina bar.

I have a widget with my stamina bar on it and created a function called: Get Stamina From Player that looks like this:

Then on my character BP

I have an Event Tick that will check my players movement and if he is running then the stamina bar decreases and if he is not running then it will slowly fill up.

Then I have a float variable called Stamina Value set to 100 that all that references to.

Oh nice, can you show a screen capture of the event tick flow.

Event Tick flow:

Part1: Screenshot by Lightshot

Part2: Screenshot by Lightshot

It’s a very messy BP as it’s being used on a 2d game i started making and haven’t touched in a while.

Thanks for sharing. Unfortunately, I couldn’t get the setup to work for what I wanted.

Are you wanting it to charge only when you take damage? or every few seconds also? not hard to setup.

Well, I have a character that can fly whenever the “tab” key is pressed and I want to limit how long he can stay flying. The idea is when the tab key is pressed and he starts flying, I want a progress bar called “Flying Energy” to show how much flying stamina he has left. When the progress bar reaches zero flying will be disabled until the flying progress bar recharges. I tried doing this:

  1. Create a variable called “inAir”.
  2. Create a variable called “flyingEnergy”.
  3. When flying key is pressed, set “inAir” to true.
  4. During “Event tick” when “inAir” is true “Delay” for 1 seconds then start subtracting from “flyingEnergy”.

------this is where things get a little confusing-------

a) How can I subtract from “flyingpower” every second “inAir” is true?
b) How can I send the value of “flyingpower” to a progress bar so it shows how much flying energy is left before the character will fall to the ground to recharge “flyingpower”?
I’m not very familiar with the many available nodes and can’t figure out which ones would work best for the job.

I’d refactor it a bit:

bool CanFly = true;
bool IsFlying = false;
float FlyingEnergy = 1.0;

Event Input Tab -> CanFly? IsFlying = true;
Event Tick -> IsFlying && CanFly = true? FlyingEnergy -= SecondsPassedThisTick/100; Add upwards force;
Event Tick -> IsFlying = false? FlyingEnergy += 0.1;
Event Tick -> FlyingEnergy < 0? CanFly = false;
Event Hit -> Did we hit the ground actor? IsFlying = false; CanFly = true;

If you want it to recharge during falling, set IsFlying to false as soon as a the key is released rather than when they hit the ground.

Doing stuff on event tick in this way isn’t recommended for secondary actors, of which you might spawn a lot. Ideally you structure this in such a way that when the energy is full and the character isn’t trying to fly, nothing happens.

Hey, thanks for this input - looking at the “IsFlying && CanFly = true?” Where do I get the SecondsPassedThisTick or rather how do I get the number of seconds after each tick?

That’s the DeltaTime pin on the Event Tick node.