Course contentsShow
← Unreal Engine Game Development
Lesson 660 of 8809. Gameplay Ability System (GAS)Free lesson

Executing Root Motion via Ability Tasks

Control character movement during specific ability windows by implementing custom tasks that apply root motion directly to the character.

In this lesson, you will learn how to orchestrate precise, character-driven movement during Gameplay Abilities by using UAbilityTask_ApplyRootMotion classes to bypass standard controller inputs.

The Problem with Standard Movement

In a standard movement setup, the CharacterMovementComponent listens to player input to calculate velocity. However, for specialized abilities like a "Dash," "Leap," or "Execution Strike," we need the animation's translation data (Root Motion) to override the movement mode entirely. If we simply trigger an animation, the character might drift or slide because the controller input is still fighting the animation's intended path.

Using Ability Tasks for Root Motion

To solve this, we use Root Motion Ability Tasks. These tasks act as a bridge between the Gameplay Ability System (GAS) and the Character Movement Component. When the task is activated, it tells the movement component to ignore standard movement vectors and instead look at the RootMotionSource provided by the task.

The workflow typically looks like this:

  1. Activation: The Ability triggers a custom Task (e.g., UAbilityTask_PlayRootMotionAndWait).
  2. Handover: The task creates a FRootMotionSource (a container for the movement path, duration, and strength).
  3. Execution: The CharacterMovementComponent receives this source and applies the movement delta directly to the character’s capsule every frame, while the Task monitors for completion or cancellation.
  4. Cleanup: Once the task finishes or is interrupted (via a Gameplay Tag or Ability end), the task removes the RootMotionSource, returning control back to the standard movement controller.
// Example: Creating a simple dash task
UAbilityTask_PlayRootMotionAndWait* Task = UAbilityTask_PlayRootMotionAndWait::CreatePlayRootMotionAndWaitProxy(
    this, 
    "DashTask", 
    MyRootMotionSource, 
    true
);
Task->Activate();

By encapsulating this in a Task, you ensure the movement is network-synced and tied specifically to the ability’s lifecycle. If the ability is canceled—perhaps due to a Stun tag—the task automatically shuts down the movement modification, preventing your character from getting stuck in a "dashing" state.

Key Takeaway: Ability Tasks provide a controlled, network-aware framework for overriding character movement via Root Motion, ensuring that custom action animations dictate character position without conflicting with standard player input.