Need help with progressbar/timers

Okay, so i have been playing around for a while now with the stamina bar. there was a lot of bugs but i fixed most of them but this one i cant figure out.i have not been able to fix it so i wonder if the community has any solutions. i have the stamina bar set up with a keyboard press instead of event tick.

the bug im trying to fix is when i run and stop while holding the shift key down the stamina bar does not fill up.

i want it to fill up. it only fills up when i let go

Hey, i tried this and it works:

Create a Widget with Progressbar, Create a Variable with type Float and Bind it. Set the Variable to 1,0.

In Player Character in Event begin Play:

Change something at the Input to get the Info if Char is moving:

And now the Main Part of reducing and refilling Stamina:

Hey, i have not tried the solution yet, but ive heard that event ticks are bad for games. but idk if this is true? but i assume you have to use event tick when it comes to stamina and health etc

and the blueprint you have created can you like walk around and still be able to gain stamina?

You can also use a Timer:

I connected the Pressed Event from Sprint to the Timer.

At the end of “Stamina up” i set the Reset for the Timer so if Stamina is full Timer gets cleard:

Yes, you should avoid using Tick events as much as possible. This is because they are run every frame and take up processing power. However, this is only really a factor when using many, many objects with tick events. It’s perfectly fine using tick event for the UI, and you don’t have to worry about performance because there is only one UI.

ahhh gotcha, so if i use lets say a tick event for 15 different functions, thats bad right?

It really depends on what the functions do… Again, if this is a single-instance object (like the UI), it shouldn’t be a problem. I mean, if you are doing 15 SetActorLocation calls or 15 math operations, it will be fine; but if you mean 15 “Write Texture to Disk” operations per tick, that will be slow.

So, if it’s your UI running 15 different standard functions per tick, it isn’t a problem

ahh okay so checking if a player moves etc shouldnt be a problem?
im new to unreal what does write to disk mean/do

By “Write Texture to Disk” I mean taking an image from your game and saving it too your computer’s hard drive.

i dont see why i should ever need that but yeah i understand. but i assume that will crash the game if ur doing it every frame. Also Thanks for helping a newbie

Also i think i fixed the problem but i havent checked for bugs yet. i used event tick to check if the player was moving or running. and that shouldnt cause it to be slower right?

No, it shouldn’t slow down the game checking if the player is moving.

Word of advice: You should have the stamina be calculated in the character’s blueprint, not the UI. Then, have the UI read the Stamina variable from the Character and display it on the bar. That way, if you want to more players (like AI), stamina will still be calculated without needing more UIs.

You dont need Event Tick for Checking if Player is moving. InputAxis Move is sending hole time, even if you are not try to move your Character.

Okay good to know, but i think i have the stamina calculated in the characters blueprint or i might not.

is the stamina calculated in the ui?

ahh i see so i can just use that instead? i will try

Yeah, with the stamina calculated in the character using the InputAxis Move event, it should just be perfect.

Yeah thanks a lot mate