Skip to content

MotionSprintingComponent

Manages sprint speed enhancement, stamina/endurance system, and camera effects during sprinting with full GAS integration. Provides input handling, state management, and networked multiplayer support.

Requirements

  • Character with standard UCharacterMovementComponent
  • MotionPlayerState configured in GameMode
  • Gameplay Ability System (GAS) initialized
  • Enhanced Input System configured
  • Gameplay Effects:
    • GE_Motion_SprintSpeed - Modifies walk speed for sprinting
    • GE_Motion_SprintStaminiaDrain - Drains stamina while sprinting (optional)
    • GE_Motion_SprintStaminiaRegen - Regenerates stamina when not sprinting (optional)
    • GE_Motion_SprintStaminiaRegenDelay - Blocks regen after exhaustion (optional)
    • GE_Motion_WantsToSprint - Grants wants to sprint tag
    • GE_Motion_Sprinting - Grants sprinting state tag
  • Gameplay Tags:
    • Motion.State.WantsToSprint - Player input to sprint
    • Motion.State.Sprinting - Active sprinting state
    • Attribute.Movement.WalkSpeed - Movement speed attribute
    • Attribute.Movement.Stamina - Stamina attribute (if using stamina)

Installation

  1. Add UMotionSprintingComponent to your Character Blueprint or C++ class
  2. Configure the component properties in the Details panel
  3. Set the SprintingTagEffect to GE_Motion_Sprinting
  4. Set the WantsToSprintTagEffect to GE_Motion_WantsToSprint
  5. Configure stamina effects if using stamina system:
    • Set SprintStaminaDrainEffect for stamina consumption
    • Set StaminaRegenEffect for recovery
    • Set StaminaRegenDelayEffect for exhaustion cooldown
  6. Bind sprint input action in Enhanced Input or through component

Functionality

Core Sprint State Machine

Sprint Update Flow

Expandability

The MotionSprintingComponent provides extensive virtual functions for customization:

Core Sprint Functions

FunctionParametersReturnsUse Case Examples
SetWantsToSprint()bool bWantsToSprintvoid• Add cooldown timer
• Check prerequisites
GetWantsToSprint()Nonebool• Query sprint intent
• UI state display
IsCurrentlySprinting()Nonebool• Check active sprint
• Animation triggers
CanStartSprinting()Nonebool• Add custom conditions
• Equipment checks

State Management Functions

FunctionParametersReturnsUse Case Examples
UpdateSprintingState()float DeltaTimevoid• Custom state logic
• Add transitions
InitializeComponent()Nonevoid• Additional setup
• Cache references
HandleSprintInputStateChange()bool bPressedvoid• Input processing
• Toggle logic
PrintDebugInformation()Nonevoid• Custom debug display
• Performance metrics

Stamina System Functions

FunctionParametersReturnsUse Case Examples
GetStaminaFromGAS()Nonefloat• Custom attribute source
• Apply modifiers
GetCurrentStamina()Nonefloat• Normalized value
• UI display
UpdateStamina()float DeltaTimevoid• Custom drain rate
• Conditional consumption
UpdateStaminaWithGameplayEffects()float DeltaTimevoid• GAS integration
• Effect management
OnStaminaAttributeChanged()FOnAttributeChangeData&void• React to changes
• Threshold checks
OnStaminaDepleted()float CurrentValuevoid• Exhaustion logic
• Apply penalties

Speed Modification Functions

FunctionParametersReturnsUse Case Examples
ApplySprintSpeedModification()Nonevoid• Apply speed boost
• Stack with buffs
RemoveSprintSpeedModification()Nonevoid• Remove speed boost
• Clear effects
GetCurrentMovementSpeed()Nonefloat• Query current speed
• Calculate multipliers
IsActuallyMoving()Nonebool• Check velocity
• Validate movement

Camera Effect Functions

FunctionParametersReturnsUse Case Examples
StartSprintCameraEffects()Nonevoid• Apply camera shake
• FOV changes
StopSprintCameraEffects()Nonevoid• Remove effects
• Smooth transition

Input System Functions

FunctionParametersReturnsUse Case Examples
OnInputStarted()FInputActionValue&void• Handle press
• Buffer input
OnInputCompleted()FInputActionValue&void• Handle release
• Toggle mode
BindSprintInput()UInputAction*bool• Bind to action
• Setup input
BindSprintInputWithComponent()UInputAction*, UEnhancedInputComponent*bool• Explicit binding
• Custom component

Blueprint Events

EventParametersUse Case Examples
OnSprintStateChangedbool bIsSprinting• Sound effects
• Animation triggers
OnSprintStaminaDepletedNone• Exhaustion VFX
• Breathing sounds
OnStaminaFullyRecoveredNone• Recovery notification
• Enable UI
OnStaminaChangedfloat NewStamina, float MaxStamina• Update stamina bar
• Warning indicators

Network Functions

FunctionParametersReturnsUse Case Examples
ServerRequestSprint()bool bWantsToSprintvoid (RPC)• Server validation
• Authority check

Configuration

Sprint Settings

PropertyTypeDefaultDescriptionRange
SprintWalkSpeedModifierfloat300.0Absolute walk speed value to add when sprinting-
bRequiresContinuousInputbooltrueWhether sprinting requires holding input or is toggle-
BaseWalkSpeedfloat600.0Base walk speed for sprint multiplier calculations100.0 - 2000.0

Stamina System

PropertyTypeDefaultDescriptionRange
bUseStaminaSystemboolfalseWhether sprinting is limited by stamina-
MinStaminaToSprintfloat1.5Minimum stamina required to start sprinting (raw value)-
MinStaminaToStopSprintingfloat0.25Minimum stamina to continue (hysteresis)-
MinSprintVelocityfloat50.0Minimum velocity required to consume stamina1.0+
RegenDelayDurationfloat2.0Duration to block regen after exhaustion0.0 - 10.0
bForceReleaseOnStaminaDepletionbooltrueForce input release after depletion-

Camera Effects

PropertyTypeDefaultDescriptionRange
SprintCameraShakeFStructMotionCurve-Camera shake curve during sprinting-
bApplyCameraShakebooltrueWhether to apply camera shake-

GAS Integration

PropertyTypeDescription
SprintSpeedEffectTSubclassOf<UGameplayEffect>Effect for sprint speed modification
SprintStaminaDrainEffectTSubclassOf<UGameplayEffect>Effect for stamina drain
StaminaRegenEffectTSubclassOf<UGameplayEffect>Effect for stamina regeneration
StaminaRegenDelayEffectTSubclassOf<UGameplayEffect>Effect blocking regen after exhaustion
MovementSpeedAttributeTagFGameplayTagTag for movement speed attribute (e.g., "Attribute.Movement.WalkSpeed")
StaminaAttributeTagFGameplayTagTag for stamina attribute (e.g., "Attribute.Movement.Stamina")

Tag Effects

PropertyTypeDescription
WantsToSprintTagEffectTSubclassOf<UGameplayEffect>Grants wants to sprint tag
SprintingTagEffectTSubclassOf<UGameplayEffect>Grants sprinting state tag

State Tracking (Read-Only)

PropertyTypeDescription
SprintCameraShakeIdentifierFStringUnique identifier for sprint camera shake
bIsLocallyPredictingboolWhether component is in local prediction state
LocalPredictedSpeedfloatLocally predicted speed value
LastLocalPredictionTimedoubleTimestamp of last prediction change

Debug

PropertyTypeDefaultDescription
bShowDebugInformationboolfalseDebug information display

Input Binding

The component provides multiple ways to bind sprint input:

Blueprint Binding

cpp
// Simple binding with auto-discovery
BindSprintInput(SprintInputAction);

// Explicit component binding
BindSprintInputWithComponent(SprintAction, EnhancedInputComponent);

Manual Binding

cpp
// Get function names for custom binding
FName StartFunction = GetSprintStartedFunctionName();
FName CompleteFunction = GetSprintCompletedFunctionName();

Stamina System

Stamina Flow Diagram

Stamina Access

  • GetCurrentStamina() - Returns normalized stamina (0.0 - 1.0)
  • GetStaminaFromGAS() - Returns raw stamina value from GAS
  • OnStaminaChanged event - Fires when stamina value changes
  • OnStaminaFullyRecovered event - Fires when stamina reaches maximum

Local Prediction

Supports client-side prediction for responsive multiplayer:

Prediction API

  • IsLocallyPredicting() - Check if in local prediction state
  • GetLocalPredictedSpeed() - Get predicted speed value
  • GetLastLocalPredictionTime() - Get timestamp of last prediction

Networking

The component handles multiplayer through:

  • Server RPCs - ServerRequestSprint() for authoritative validation
  • Client Prediction - Immediate local feedback
  • GAS Replication - Automatic effect synchronization
  • State Reconciliation - Smooth correction of mispredictions

Motion - Advanced First Person Character Controller