Skip to content

MotionAbilitySystemHelper

Helper functions for integrating Motion with Unreal's Gameplay Ability System. The library covers Enhanced Input discovery, ASC lookup and initialization, gameplay tag operations, effect-backed tag application, universal attribute discovery, and platform-relative movement helpers.

ASC Discovery

GetEnhancedInputComponentFromActor(Actor, bLogErrors=false)

Returns the actor's UEnhancedInputComponent, or nullptr if no enhanced input component is found.

GetAbilitySystemComponentFromActor(Actor, bLogErrors=false)

Finds an UAbilitySystemComponent through IAbilitySystemInterface on the actor or its PlayerState.

Attribute Discovery

These functions let Motion work with project-specific AttributeSets by resolving attributes by name.

FindAttributeByName(ASC, AttributeName)

Searches all AttributeSets on the ASC for an attribute with the given name.

Returns: FGameplayAttribute, or an invalid attribute when no match is found.

GetAttributeValueByName(ASC, AttributeName, OutValue)

Reads the current value of an attribute by name.

Returns: true when the attribute exists.

SetAttributeValueByName(ASC, AttributeName, NewValue)

Sets the base value of an attribute by name.

Returns: true when the attribute exists.

HasAttributeByName(ASC, AttributeName)

Checks whether an attribute with the given name exists on the ASC.

SyncWalkSpeedToCharacterMovement(Character, NewWalkSpeed, OldWalkSpeed, bUpdateCrouchedSpeed=true)

Applies a walk speed value to the character's CharacterMovementComponent->MaxWalkSpeed.

When bUpdateCrouchedSpeed is true, the helper also updates MaxWalkSpeedCrouched proportionally by preserving its ratio to the previous standing walk speed. Motion uses this shared helper from MotionAttributeSet during WalkSpeed changes and from MotionWalkComponent during assigned walk profile BaseWalkSpeed initialization.

Attribute Example

cpp
FGameplayAttribute WalkSpeedAttr =
    UMotionAbilitySystemHelper::FindAttributeByName(ASC, "WalkSpeed");

if (WalkSpeedAttr.IsValid())
{
    float Value = ASC->GetNumericAttribute(WalkSpeedAttr);
}

float CurrentStamina = 0.0f;
if (UMotionAbilitySystemHelper::GetAttributeValueByName(ASC, "Stamina", CurrentStamina))
{
    // Use the stamina value.
}

if (UMotionAbilitySystemHelper::HasAttributeByName(ASC, "JumpVelocity"))
{
    // Jump velocity attribute is available.
}

Gameplay Tags

ActorHasGameplayTag(Actor, Tag)

Checks whether the actor's ASC has the specified GameplayTag.

AddGameplayTagToActor(Actor, Tag)

Adds a loose GameplayTag to the actor's ASC.

RemoveGameplayTagFromActor(Actor, Tag)

Removes a loose GameplayTag from the actor's ASC.

ApplyGameplayTagEffect(Actor, EffectClass)

Applies a UGameplayEffect that grants tags.

Returns: active effect handle.

RemoveGameplayTagEffect(Actor, EffectHandle)

Removes a previously applied tag-granting effect by handle.

ApplyTagEffectFromClass(Actor, EffectClass, FallbackTag)

Applies EffectClass. If the effect cannot be applied, falls back to adding FallbackTag as a loose tag.

RemoveTagEffectWithFallback(Actor, EffectHandle, FallbackTag)

Removes the tag effect and its fallback loose tag. This is idempotent and handles the case where ApplyTagEffectFromClass used either a GameplayEffect or a loose tag.

ASC Initialization

InitializeCharacterAbilitySystem(Character, bLogErrors=true)

Initializes ASC owner/avatar bindings for a character.

InitializeCharacterAbilitySystemWithAttributeSet(Character, AttributeSetClass, bLogErrors=true, AttributeDataTable=nullptr, bLogDataTableDetails=false)

Initializes ASC owner/avatar bindings, ensures the requested UAttributeSet exists, and can initialize values from a DataTable.

InitializeAttributeSetFromDataTable(ASC, AttributeDataTable, AttributeSetClass=nullptr, bLogDetails=false)

Calls InitFromMetaDataTable on one AttributeSet class or on all AttributeSets in the ASC.

Movement Helpers

GetPlatformRelativeVelocity(CMC)

Returns character velocity relative to the moving platform the character is standing on. This subtracts platform velocity for locomotion calculations.

GetPlatformRelativeSpeed(CMC)

Returns the magnitude of platform-relative velocity.

Motion - Advanced First Person Character Controller