Skip to content

MotionCrouchingComponent

Manages crouch state using Unreal's native crouch system with GAS integration, speed modifiers, and ceiling collision detection. The component wraps Character->Crouch()/UnCrouch() functions with additional features like speed effects and tag management.

Requirements

  • Character with standard UCharacterMovementComponent and UCapsuleComponent
  • MotionPlayerState configured in GameMode
  • Gameplay Ability System (GAS) initialized
  • Enhanced Input System configured
  • Gameplay Effects:
    • GE_Motion_CrouchSpeed - Modifies walk speed while crouching
    • GE_Motion_WantsToCrouch - Grants wants to crouch tag
    • GE_Motion_Crouching - Grants crouching state tag
  • Gameplay Tags:
    • Motion.State.WantsToCrouch - Player input to crouch
    • Motion.State.Crouching - Active crouching state
    • Attribute.Movement.WalkSpeed - Movement speed attribute

Installation

  1. Add UMotionCrouchingComponent to your Character Blueprint or C++ class
  2. Configure the component properties in the Details panel
  3. Set the CrouchingTagEffect to GE_Motion_Crouching
  4. Set the WantsToCrouchTagEffect to GE_Motion_WantsToCrouch
  5. Configure CapsuleHalfHeightWhenCrouching (default: 48.0)
  6. Set CrouchSpeedEffect to GE_Motion_CrouchSpeed for GAS-based speed modification
  7. Bind crouch input action in Enhanced Input or through component

Functionality

The component uses Unreal's built-in Character crouch system with automatic server replication, while the camera component handles its own height interpolation separately.

Crouch State Machine

Update Flow

Expandability

The MotionCrouchingComponent provides virtual functions for customization:

Core Crouch Functions

FunctionParametersReturnsUse Case Examples
SetWantsToCrouch()bool bWantsToCrouchvoid• Add cooldown timer
• Check prerequisites
GetWantsToCrouch()Nonebool• Query crouch intent
• UI state display
IsCurrentlyCrouching()Nonebool• Check active crouch
• Animation triggers
IsFullyCrouched()Nonebool• Verify crouch active
• Enable abilities
IsUncrouchBlocked()Nonebool• Check ceiling collision
• Show UI warning
GetCurrentCapsuleHalfHeight()Nonefloat• Query capsule height
• Calculate positions

State Management Functions

FunctionParametersReturnsUse Case Examples
UpdateCrouchingState()float DeltaTimevoid• Custom state logic
• Monitor changes
InitializeComponent()Nonevoid• Additional setup
• Cache references
HandleCrouchInputStateChange()bool bPressedvoid• Process input
• Toggle mode

Collision Detection Functions

FunctionParametersReturnsUse Case Examples
GetCapsuleOverlapResult()const FVector& TestLocation, float TestHeightbool• Test collisions
• Validate space

GAS Integration Functions

FunctionReturnsUse Case Examples
ApplyCrouchSpeedModification()void• Apply speed effect
• Stack with abilities
RemoveCrouchSpeedModification()void• Remove speed effect
• Clear modifiers
GenerateCurveIdentifier()FString• Unique IDs
• Multi-component

Input System Functions

FunctionParametersReturnsUse Case Examples
OnInputStarted()const FInputActionValue& Valuevoid• Handle press
• Start crouch
OnInputCompleted()const FInputActionValue& Valuevoid• Handle release
• Stop crouch
BindCrouchInput()UInputAction* CrouchActionbool• Bind action
• Setup input
BindCrouchInputWithComponent()UInputAction* CrouchAction, UEnhancedInputComponent* InputComponentbool• Explicit binding
• Custom component

Debug Functions

FunctionParametersReturnsUse Case Examples
PrintDebugInformation()Nonevoid• Debug display
• State logging

Blueprint Events

EventParametersUse Case Examples
OnCrouchStateChangedbool bIsCrouching• Animation triggers
• Sound effects
OnCrouchBlockedNone• UI notification
• Warning sound
OnCrouchTransitionCompletedbool bIsNowCrouched• State confirmation
• Enable abilities

Network Functions

FunctionParametersReturnsUse Case Examples
ServerRequestCrouch()bool bWantsToCrouchvoid (RPC)• Server validation
• Authority check

Configuration

Crouch Settings

PropertyTypeDefaultDescriptionRange
CapsuleHalfHeightWhenCrouchingfloat48.0Target capsule half height when fully crouched10.0 - 200.0
CrouchWalkSpeedModifierfloat-200.0Absolute walk speed value to add when crouching (negative to slow)-

GAS Integration

PropertyTypeDescription
CrouchSpeedEffectTSubclassOf<UGameplayEffect>Effect for crouch speed modification (GAS-only)
MovementSpeedAttributeTagFGameplayTagTag for movement speed attribute (e.g., "Attribute.Movement.WalkSpeed")
WantsToCrouchTagEffectTSubclassOf<UGameplayEffect>Grants wants to crouch tag
CrouchingTagEffectTSubclassOf<UGameplayEffect>Grants crouching state tag

Internal State (Read-Only)

PropertyTypeDescription
ActiveCrouchSpeedEffectHandleFActiveGameplayEffectHandleHandle to active speed modifier effect
WantsToCrouchTagHandleFActiveGameplayEffectHandleHandle to wants to crouch tag effect
CrouchingTagHandleFActiveGameplayEffectHandleHandle to crouching state tag effect

State Tracking (Read-Only)

PropertyTypeDescription
OriginalCapsuleHalfHeightfloatOriginal capsule half height cached at BeginPlay
CachedCapsuleComponentUCapsuleComponent*Cached reference to capsule component
CachedCameraComponentUMotionCameraComponent*Cached reference to camera component (for notifications)
bWasCrouchedLastFrameboolPrevious frame's bIsCrouched state for change detection
bWasCrouchingLastFrameboolPrevious frame's crouching tag state
LastCrouchRPCTimefloatServer RPC rate limiting (for custom ServerRequestCrouch)

Debug

PropertyTypeDescription
bShowDebugInformationboolDebug information display

Input Binding

The component provides multiple ways to bind crouch input:

cpp
// Blueprint binding
BindCrouchInput(CrouchInputAction);

// C++ with explicit component
BindCrouchInputWithComponent(CrouchAction, EnhancedInputComponent);

State Access

Query crouch state for gameplay logic:

  • GetWantsToCrouch() - Check if player wants to crouch (input held)
  • IsCurrentlyCrouching() - Returns Character->bIsCrouched
  • IsFullyCrouched() - Same as IsCurrentlyCrouching() (instant transition)
  • IsUncrouchBlocked() - Check if ceiling blocks standing via Character->CanCrouch()
  • GetCurrentCapsuleHalfHeight() - Get current capsule half height

Architecture Summary

MotionCrouchingComponent acts as a wrapper and coordinator for Unreal's native crouch system:

  • Does NOT handle capsule resizing - CharacterMovementComponent does this
  • Does NOT interpolate heights - Camera component handles its own interpolation
  • DOES manage - Input, GAS effects, tags, and coordination between systems
  • DOES provide - Blueprint events, state queries, and debugging

Local Prediction

Leverages native prediction system:

  • Character->Crouch() - Automatically handles prediction and server RPC
  • CharacterMovementComponent - Built-in rollback support
  • bIsCrouched - Authoritative state from server
  • No custom prediction tracking - Uses UE5's native system

Networking

The component handles multiplayer through:

  • Native crouch RPCs - Character->Crouch() includes built-in server RPC
  • CharacterMovementComponent replication - Automatic bIsCrouched sync
  • GAS effect synchronization - Speed and tag effects replicate
  • Camera independence - Each client interpolates camera locally

Motion - Advanced First Person Character Controller