Skip to content

How to use Gameplay Ability System patterns with Motion

Use this guide after you understand the Motion Gameplay Ability System (GAS) model. This guide gives usual implementation patterns.

Initialize the character Ability System Component (ASC)

Motion works best when the replicated ASC lives on PlayerState and the character initializes owner/avatar bindings after possession:

cpp
UMotionAbilitySystemHelper::InitializeCharacterAbilitySystem(Character, true);

Create and initialize your custom AttributeSet in your ASC setup. If no UMotionAttributeSet exists, a Motion component creates that supplied set on the server. It does this after ASC initialization. For custom DataTable defaults, call Unreal InitFromMetaDataTable on your AttributeSet. Use rows such as MotionAttributeSet.WalkSpeed.

Read state tags

Use Motion helper functions when gameplay logic branches on movement state:

cpp
const bool bIsSprinting = UMotionAbilitySystemHelper::ActorHasGameplayTag(
    Character,
    MotionGameplayTags::Motion_State_Sprinting
);

Use server-applied GameplayEffects for replicated state. Use loose tags for predicted intent or locally derived presentation state, never as replicated truth.

Keep intent and active state separate. For example, Motion.State.WantsToSprint can be true while the character is idle, blocked, or out of stamina. Motion.State.Sprinting must be true only during active sprinting. If you locally predict an active state tag, add a correction path for each server-side rejection.

When a component supports the two paths, pair ApplyTagEffectFromClass with RemoveTagEffectWithFallback:

cpp
FActiveGameplayEffectHandle SprintingHandle =
    UMotionAbilitySystemHelper::ApplyTagEffectFromClass(
        Character,
        SprintingTagEffect,
        MotionGameplayTags::Motion_State_Sprinting
    );

UMotionAbilitySystemHelper::RemoveTagEffectWithFallback(
    Character,
    SprintingHandle,
    MotionGameplayTags::Motion_State_Sprinting
);

On the server, a valid GameplayEffect handle represents replicated state. On a predicting client or failed effect path, the fallback loose tag is local and the handle can be invalid.

Apply a temporary speed modifier

  1. Create a GameplayEffect that modifies WalkSpeed.
  2. Select Duration when the modifier has an automatic end. Select Infinite when code removes it.
  3. Apply the effect on the server:
cpp
FGameplayEffectContextHandle Context = ASC->MakeEffectContext();
FGameplayEffectSpecHandle Spec = ASC->MakeOutgoingSpec(SpeedBuffEffect, 1.0f, Context);
if (Spec.IsValid())
{
    ASC->ApplyGameplayEffectSpecToSelf(*Spec.Data.Get());
}

Before you apply effects from component code, make sure that the ASC is initialized. Apply attribute and modifier effects from initialized server code.

React to attribute changes

Bind to the ASC attribute delegate during component initialization:

cpp
ASC->GetGameplayAttributeValueChangeDelegate(
    UMotionAttributeSet::GetStaminaAttribute()
).AddUObject(this, &UMyComponent::OnStaminaChanged);

Keep UI, audio, and cosmetic reactions local. Keep gameplay decisions on the server.

Read and write attributes by name

Motion helpers and component-specific lookup paths can read custom AttributeSets when those sets expose the expected property names:

cpp
float CurrentStamina = 0.0f;
if (UMotionAbilitySystemHelper::GetAttributeValueByName(
        ASC,
        TEXT("Stamina"),
        CurrentStamina))
{
    // Use current stamina for UI or local gating.
}

FindAttributeByName and GetAttributeValueByName are safe lookup helpers. For writes, use GameplayEffects for gameplay changes or SetNumericAttributeBase in specified initialization code. To control Motion movement from project attributes, retarget the profile GameplayEffects. Add equivalent synchronization to CharacterMovementComponent where the supplied UMotionAttributeSet usually owns it.

Configure custom movement states

  1. Define a project GameplayTag such as Motion.State.Sliding.
  2. Create a GameplayEffect that grants the tag.
  3. Map the tag to an Animation Blueprint property when it applies to animation.
  4. Add specified checks for the custom state in each Motion component condition that must reject it. GameplayEffect application requirements only control whether that effect can apply. They do not make native Motion components identify a new blocking state without configuration.

If the state has owner-visible animation or camera feedback, decide whether the owning client must predict the active state tag. Predicted tags must apply only to the locally controlled character. Remove them when the server accepts, rejects, or replaces the state.

For a broader recipe collection, see How to customize Motion movement behavior.

Motion - Advanced First Person Character Controller