I Made a Stamina system. that need fixes

I made a stamina system for a multiplayer survival game so when I hold the shift key I start running and the stamina drains but when I let go of the hold shift it still drains and I have to stop, and it start going back but i want it to regenerate while i walk after letting go in shift key

Sprint

Sprint posted by pevpev | blueprintUE | PasteBin For Unreal Engine

Drain stamina attached to Movement Input

Drain stamina attached to Movement Input posted by pevpev | blueprintUE | PasteBin For Unreal Engine

Drain and regen stamina event graph

Drain and regen stamina event graph posted by pevpev | blueprintUE | PasteBin For Unreal Engine

FRegenStam

FRegenStam posted by pevpev | blueprintUE | PasteBin For Unreal Engine

FDrainStam

FDrainStam posted by pevpev | blueprintUE | PasteBin For Unreal Engine

Hello There,

I skim through the scipts,

So there are multiple culprits here in the scripts but what essentially happenning : Player’s stamina after reaching less then 0.25 marks bStamLow so after a certain value it goes lower but never stops draining (probably stuck at close to 0) since when you even let go shift it fails on input side here :

This never triggers sprinting off bool. Even though speed seems to change cause you set those on the Stamina function already.

Btw there is a much effective and a simpler way of doing this, I see that there is many bools making debugging a bit hard. There can be some logic gates which functions does what and that would be much easier to craft also much more efficient.

1- Input : Let’s treat the player input just player wants to do something. Like bWantsToSprint. Making bool like this is basically telling yourself and systems, player tries to sprint but we don’t know if they are sprinting or not or their speed. So I suggest you remove speed functions from there. bWantsToSprint true or false.

2- Handling : So after player wants to spring we can do things on the tick easiest way, it’s not a big load and its better sometimes to handle movement on tick since your design dependent on stamina currency / attribute

What we do , we check if this wants sprint and have stamina enough we decrease and set movement mode. If not we regen / give stamina and set movement mode.

Additionally before function ends /exists we consider stamina status (StaminaLow) if Low set movement mode, if very low again set movement mode. Before we exit status we select the correct movement mode speed and set character.

Character movement is replicated by default so you don’t have to too much worry about it. However if you want for some reason you can do like this ( you already do a RPC call)

UI can be standalone, we don’t have to tell can listen.

Should be acting something like below

There is other ways to handle this, including service, GAS Ability etc. Let me know if this is valuable. Just wanted to point out that it can be more simpler with respect to what you have done so far however the bug mentioned in the first paragraph can also be fixed.

Also don’t hesitate to articulate design behaviour if you looking for something specific in design.

  • Regen with different aspects
  • Regen curves
  • Drain / cost only when can sprint.
  • Drain / cost with different aspects

etc.