Skip to content

Motion Subsystem

The Motion Subsystem provides centralized orchestration for all Motion components on a player's character. It's a LocalPlayerSubsystem that manages component registration, ability granting, and cross-component coordination.

Overview

UMotionSubsystem is automatically created for each local player and provides:

  • Central registry of active Motion components
  • Automatic movement ability granting
  • Component query interface
  • Lifecycle management

Accessing the Subsystem

Blueprint

blueprint
Get Local Player Subsystem (Motion Subsystem)
└── Returns: Motion Subsystem Reference

C++

cpp
// From Player Controller
UMotionSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UMotionSubsystem>(
    PlayerController->GetLocalPlayer()
);

// From any Actor with player context
if (APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
    UMotionSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UMotionSubsystem>(
        PC->GetLocalPlayer()
    );
}

Key Functions

Query Components

cpp
// Get all registered Motion components
TArray<UMotionComponentBase*> Components = Subsystem->GetActiveComponents();

// Get specific component type
UMotionWalkComponent* WalkComp = Cast<UMotionWalkComponent>(
    Subsystem->GetComponentByClass(UMotionWalkComponent::StaticClass())
);

// Check if a component type is registered
bool bHasSprintComp = Subsystem->GetComponentByClass(UMotionSprintingComponent::StaticClass()) != nullptr;

Grant Movement Abilities

cpp
// Auto-grant movement abilities to an ASC
Subsystem->GrantMovementAbilities(AbilitySystemComponent);

// Remove previously granted abilities
Subsystem->RemoveMovementAbilities(AbilitySystemComponent);

By default, GrantMovementAbilities() grants nothing. To specify which abilities to auto-grant, either:

  1. Subclass UMotionSubsystem and override GetDefaultMovementAbilities()
  2. Configure abilities via a data asset

Note

Motion components handle movement directly. GAS abilities are optional and used for state management integration.

Multiplayer

Call GrantMovementAbilities() and RemoveMovementAbilities() on the server (authority) for abilities to replicate properly.

Component Registration

Motion components automatically register/unregister with the subsystem. You generally don't need to call these manually:

cpp
// Components call these in BeginPlay/EndPlay
Subsystem->RegisterComponent(MotionComponent);
Subsystem->UnregisterComponent(MotionComponent);

Use Cases

Cross-Component Coordination

Use the subsystem to coordinate between components:

cpp
void MySystem::HandleEvent()
{
    UMotionSubsystem* Subsystem = GetSubsystem();

    // Check if player is sprinting before applying effect
    if (auto* SprintComp = Cast<UMotionSprintingComponent>(
        Subsystem->GetComponentByClass(UMotionSprintingComponent::StaticClass())))
    {
        if (SprintComp->IsCurrentlySprinting())
        {
            // Don't apply slow while sprinting
            return;
        }
    }

    ApplySlowEffect();
}

Debug All Components

cpp
void DebugMotionState()
{
    UMotionSubsystem* Subsystem = GetSubsystem();

    for (UMotionComponentBase* Comp : Subsystem->GetActiveComponents())
    {
        UE_LOG(LogTemp, Log, TEXT("Active: %s"), *Comp->GetClass()->GetName());
    }
}

Initialize Movement System

When setting up a character:

cpp
void AMyCharacter::PossessedBy(AController* NewController)
{
    Super::PossessedBy(NewController);

    // Ensure movement abilities are granted
    if (APlayerController* PC = Cast<APlayerController>(NewController))
    {
        if (UMotionSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UMotionSubsystem>(PC->GetLocalPlayer()))
        {
            if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
            {
                Subsystem->GrantMovementAbilities(ASC);
            }
        }
    }
}

Subsystem Lifecycle

  1. Creation - Automatically created when local player is initialized
  2. Registration - Motion components register in BeginPlay
  3. Active - Subsystem provides coordination during gameplay
  4. Cleanup - Components unregister in EndPlay

See Also

Motion - Advanced First Person Character Controller