Stamina/Sprint System

Hi! I wanted to create a stamina system and tried to look up something on youtube but I found only very massive codes and it felt like very perfomance heavy ( I am only a beginner and don’t know if It’s like so). I wanted to try my own version and I came up with something. I think it works fine and I can expand it later if needed but there is still one problem that I’d like to solve and don’t know how. Her is my code

‘Stamina --’ function

‘Stamina ++’ function

There are some things that I wanted to implement so the code became a little bit messier like for example continuing sprint after attack if shift is still pressed:

So here is the problem that I encountered:


If I press shift many times while attacking it executes ‘clear timer by function name’ and then turns it on again so replenishing stamina takes more time, I don’t know how to fix this with my code setup right now. I would be very happy for any suggestions.

Also if anyone can tell if this is perfomance heavy or not, because I don’t know how to measure those things if it’s not some huge implementation

Thanks!!!

IMO move all stamina logic to an actor component and set it with a custom component tick interval. Disable tick when stamina == max stamina and enable tick when player presses to sprint.