Skip to content

Stamina

Jared Taylor edited this page Jun 30, 2025 · 7 revisions

Important

This is largely irrelevant to Blueprint users on the single-cmc branch

Add a void CalcStamina(float DeltaTime) function to your UCharacterMovementComponent and call it before Super after overriding CalcVelocity.

You will want to implement what happens based on the stamina yourself, eg. override GetMaxSpeed to move slowly when bStaminaDrained.

Override OnStaminaChanged to call (or not) SetStaminaDrained based on the needs of your project. Most games will want to make use of the drain state to prevent rapid sprint re-entry on tiny amounts of regenerated stamina. However, unless you require the stamina to completely refill before sprinting again, then you'll want to override OnStaminaChanged and change FMath::IsNearlyEqual(Stamina, MaxStamina) to multiply MaxStamina by the percentage that must be regained before re-entry (eg. MaxStamina0.1f is 10%).

Nothing is presumed about regenerating or draining stamina, if you want to implement those, do it in CalcVelocity or at least PerformMovement - CalcVelocity stems from PerformMovement but exists within the physics subticks for greater accuracy.

If used with sprinting, OnStaminaDrained() should be overridden to call USprintMovement::UnSprint(). If you don't do this, the greater accuracy of CalcVelocity is lost because it cannot stop sprinting between frames.

You will need to handle any changes to MaxStamina, it is not predicted here.

GAS can modify the Stamina (by calling SetStamina(), nothing special required) and it shouldn't desync, however if you have any delay between the ability activating and the stamina being consumed it will likely desync; the solution is to call GetCharacterMovement()->FlushServerMoves() from the Character. It is worthwhile to expose this to blueprint. The correction mechanism implemented in UStaminaMovement::ServerCheckClientError will trigger a correction if the Stamina desyncs in 2 units by default (see UStaminaMovement::NetworkStaminaCorrectionThreshold). Note that Stamina corrections won't necessarily correct also our character Transform.

This is not designed to work with blueprint, at all, anything you want exposed to blueprint you will need to do it Better yet, add accessors from your Character and perhaps a broadcast event for UI to use.

This solution is provided by Cedric 'eXi' Neukirchen and has been repurposed for net predicted Stamina.

Clone this wiki locally