# Stamina/Sprint System

**URL:** <https://forums.unrealengine.com/t/stamina-sprint-system/501784>\
**Category:** Blueprint\
**Tags:** stamina, unreal-engine, UE4-27\
**Created:** [February 24, 2022, 1:14pm UTC](https://forums.unrealengine.com/t/stamina-sprint-system/501784 "2022-02-24T13:14:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eromanga](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eromanga](https://forums.unrealengine.com/u/eromanga)\
**Post date:** [February 24, 2022, 1:14pm UTC](https://forums.unrealengine.com/t/stamina-sprint-system/501784/1 "2022-02-24T13:14:45Z")

</div>

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

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/a/e/baefa5b1200bc98671e16d1737b5dd501457911d.png)

‘Stamina --’ function

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/a/f/eafca0780671c757eaa8bc720b59730f796e13b8.png)

‘Stamina ++’ function

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/2/0/6206d75a6e0b7bd7e2f678b32f99bb84b0c7d3be.png)

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:

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/c/1/ac13f6096097b191be41a0c394b39624fc51c073.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/c/1/ac13f6096097b191be41a0c394b39624fc51c073.mp4)

So here is the problem that I encountered:

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/1/631afc6cb14b5f73345010e137198ba7cb47d629.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/1/631afc6cb14b5f73345010e137198ba7cb47d629.mp4)
  
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!!!

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [February 25, 2022, 6:22am UTC](https://forums.unrealengine.com/t/stamina-sprint-system/501784/2 "2022-02-25T06:22:03Z")

</div>

> [@eromanga](#):
>
> 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

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.
