Skip to content

MotionAnimInstance

Advanced Animation Instance providing automatic GAS tag-to-property mapping, sophisticated ground distance calculations, and comprehensive caching system for high-performance animation blueprints. Features intelligent ASC binding with fallback mechanisms and frame-accurate ground information.

Requirements

  • Character with Animation Blueprint
  • MotionPlayerState configured in GameMode
  • Gameplay Ability System (GAS) initialized
  • Parent Class: Animation Blueprint must inherit from UMotionAnimInstance
  • Component Dependencies: Automatically detects Character, CharacterMovementComponent, and CapsuleComponent
  • Caching System: Frame-based caching for optimal performance

Installation

  1. Create or open your Animation Blueprint
  2. In Class Settings, set Parent Class to MotionAnimInstance
  3. Configure the GameplayTagPropertyMap in Class Defaults
  4. Map gameplay tags to animation blueprint variables
  5. The instance will auto-bind to the character's Ability System Component
  6. Ground information will be automatically calculated and cached
  7. All component references are cached for performance

Image Placeholder: Animation Blueprint class settings showing MotionAnimInstance as parent

Functionality

MotionAnimInstance automatically syncs GAS tags with animation blueprint properties and provides utility functions.

Animation Instance Initialization Flow

ASC Binding State Machine

Virtual Functions

Core Animation Functions

FunctionParametersReturn TypeDescription
NativeInitializeAnimation()NonevoidOverride to initialize custom animation systems
NativeUninitializeAnimation()NonevoidOverride to cleanup custom animation systems
NativeUpdateAnimation()float DeltaSecondsvoidOverride to add custom animation update logic
InitializeWithAbilitySystem()UAbilitySystemComponent* ASCvoidInitialize the animation instance with AbilitySystemComponent

Ground Detection Functions

FunctionParametersReturn TypeDescription
GetGroundInfo()NoneFMotionGroundInfoCalculate and cache ground distance information

ASC Integration Functions

FunctionParametersDescription
OnAbilitySystemAvailable()UAbilitySystemComponent* ASCCalled when ASC becomes available via delegate

Editor Validation Functions

FunctionParametersReturn TypeDescription
IsDataValid()FDataValidationContext& ContextEDataValidationResultValidate animation data and tag mappings (Editor only)

Configuration Properties

Gameplay Tag Property Mapping

PropertyTypeDescription
GameplayTagPropertyMapFGameplayTagBlueprintPropertyMapMaps gameplay tags to Blueprint properties for automatic updates

Animation State Properties

PropertyTypeCategoryDescription
GroundDistancefloatCharacter State DataDistance to ground below character (cached per frame)
bIsAbilitySystemBoundboolMotion AnimationWhether successfully bound to AbilitySystemComponent

Ground Information Structure

FMotionGroundInfo provides comprehensive ground detection:

PropertyTypeDescription
GroundHitResultFHitResultComplete hit information from ground trace
GroundDistancefloatDistance to ground (-1.0 if no ground detected)
LastUpdateFrameuint32Frame number when last updated for caching

Read-Only State Properties

Cached Component References

PropertyTypeDescription
CachedCharacterACharacter*Cached reference to the owning character
CachedCharacterMovementUCharacterMovementComponent*Cached reference to character movement component
CachedCapsuleComponentUCapsuleComponent*Cached reference to capsule component
CachedAbilitySystemComponentUAbilitySystemComponent*Cached reference to the ASC

Internal State Tracking

PropertyTypeDescription
CachedGroundInfoFMotionGroundInfoCached ground information to avoid redundant calculations
bIsAbilitySystemBoundboolFlag tracking successful ASC binding
bIsWaitingForAbilitySystemDelegateboolFlag tracking delegate callback waiting state
bShouldRetryASCBindingboolFlag tracking need to retry ASC binding

Gameplay Tag Property Mapping Setup

In the Animation Blueprint's Class Defaults:

  1. Find GameplayTagPropertyMap
  2. Add entries for each tag-to-property mapping:
    • Tag: Motion.State.Walking
    • Property Name: bIsWalking
    • Property Type: Boolean

Common Motion Tag Mappings

Gameplay TagProperty NameTypeUsage
Motion.State.WalkingbIsWalkingBoolWalking animation state
Motion.State.SprintingbIsSprintingBoolSprint animation state
Motion.State.CrouchingbIsCrouchingBoolCrouch animation state
Motion.State.JumpingbIsJumpingBoolJump/fall animation state
Motion.State.WantsToSprintbWantsToSprintBoolSprint intention
Motion.State.WantsToCrouchbWantsToCrouchBoolCrouch intention
Motion.State.InAirbIsInAirBoolAirborne state
Motion.State.OnGroundbIsOnGroundBoolGrounded state

Advanced Ground Detection System

Sophisticated ground information with frame-based caching:

cpp
// FMotionGroundInfo structure provides:
struct FMotionGroundInfo
{
    FHitResult GroundHitResult;     // Complete collision information
    float GroundDistance;           // Distance to ground (-1.0 if none)
    uint32 LastUpdateFrame;         // Frame number for caching
};

Ground Detection Features

  • Frame-Accurate Caching: Updates only once per frame for performance
  • Complete Hit Information: Full collision data including surface normal
  • Automatic Fallback: Returns -1.0 when no ground is detected
  • Performance Optimized: Cached results prevent redundant calculations
  • Blueprint Accessible: Direct access to GroundDistance property

Animation Blueprint Setup

cpp
// In your Animation Blueprint Event Graph
Event Blueprint Update Animation
├── Get Ground Distance
│   └── Use for foot IK or landing preparation
├── Check bIsWalking
│   └── Transition to walk state
├── Check bIsSprinting
│   └── Apply sprint pose
└── Check bIsCrouching
    └── Adjust crouch animations

Automatic ASC Binding

The system handles ASC availability automatically:

  1. Attempts immediate binding on initialization
  2. If PlayerState not ready, registers delegate
  3. Retries binding when ASC becomes available
  4. Handles both client and server scenarios

Advanced Features

Intelligent ASC Binding System

Sophisticated binding mechanism with multiple fallback strategies:

cpp
// Binding attempt priority:
1. Immediate binding (PlayerState ready, ASC available)
2. Delegate registration (PlayerState ready, ASC not yet initialized)
3. Retry mechanism (PlayerState not ready, check each frame)
4. Graceful degradation (function without ASC if necessary)

Binding State Management

  • bIsAbilitySystemBound: Tracks successful ASC connection
  • bIsWaitingForAbilitySystemDelegate: Waiting for delegate callback
  • bShouldRetryASCBinding: Needs retry in next update cycle

Performance Optimization Features

Frame-Based Caching System

cpp
// Ground information cached per frame
if (CachedGroundInfo.LastUpdateFrame != GFrameNumber)
{
    // Perform expensive ground trace
    CachedGroundInfo = PerformGroundTrace();
    CachedGroundInfo.LastUpdateFrame = GFrameNumber;
}
// Use cached result for all subsequent calls this frame
return CachedGroundInfo;

Component Reference Caching

  • Initialization Caching: All component references cached once
  • Null Checking: Safe access patterns with validation
  • Memory Efficient: Minimal overhead per animation instance

Optimized Tag Processing

  • Direct ASC Access: No component searches during updates
  • Batch Processing: All tag mappings processed together
  • Conditional Updates: Skip processing when ASC unavailable

Blueprint Integration

After inheriting from MotionAnimInstance, you gain access to:

Built-in Variables

VariableTypeCategoryDescription
GroundDistancefloatCharacter State DataCurrent distance to ground
bIsAbilitySystemBoundboolMotion AnimationASC binding status

Auto-Mapped Variables

All properties defined in GameplayTagPropertyMap:

  • Automatically Updated: Each frame based on ASC tags
  • Type-Safe Access: Full Blueprint IntelliSense support
  • Performance Optimized: Direct property updates, no Blueprint calls

Advanced Blueprint Nodes

blueprint
# Ground Information Access
Get Ground Info → Motion Ground Info Struct
├── Ground Hit Result → Hit Result
├── Ground Distance → Float  
└── Last Update Frame → Integer

# Binding Status Check
Is Ability System Bound → Boolean

# Component Access
Get Cached Character → Character Reference
Get Cached Character Movement → Character Movement Component
Get Cached Capsule Component → Capsule Component

Common Use Cases

State Machine Transitions

Can Enter Walk State:
- bIsWalking AND NOT bIsSprinting

Can Enter Sprint State:
- bIsSprinting AND GroundDistance <= 0

Can Enter Jump State:
- bIsJumping OR GroundDistance > 100

Blend Spaces

  • Use mapped properties for blend space axes
  • Combine with velocity for directional blending
  • Apply ground distance for landing preparation

Animation Notifiers

  • Check state properties before triggering sounds
  • Validate movement state for particle effects
  • Coordinate with MotionMovementSoundComponent

Debugging and Troubleshooting

Console Commands

Enable comprehensive logging for debugging:

console
# Motion animation system logging
log LogMotionAnimation Verbose
log LogMotionCore Verbose

# Ability system integration logging
log LogAbilitySystem Verbose
log LogGameplayTags Verbose

# Animation system logging
log LogAnimation Verbose
log LogAnimBlueprint Verbose

# Performance monitoring
stat anim
stat game

Common Issues and Solutions

Properties Not Updating

Problem: Gameplay tag properties not reflecting ASC state
Solutions:

cpp
// Check GameplayTagPropertyMap configuration
1. Verify tag names match exactly (case sensitive)
2. Ensure property names exist in Blueprint
3. Confirm property types are correct (Bool for most tags)
4. Check bIsAbilitySystemBound is true in runtime

ASC Not Binding

Problem: bIsAbilitySystemBound remains false
Solutions:

  • Verify MotionPlayerState is set in GameMode
  • Check PlayerState initialization timing
  • Monitor bShouldRetryASCBinding and bIsWaitingForAbilitySystemDelegate flags
  • Ensure ASC is properly initialized on PlayerState

Ground Distance Issues

Problem: GroundDistance returning incorrect values
Solutions:

cpp
// Check capsule component setup
1. Verify capsule component exists and is properly configured
2. Ensure collision channels are set correctly
3. Check trace distance and collision settings
4. Monitor CachedGroundInfo.LastUpdateFrame for caching issues

Performance Problems

Problem: Animation updates causing frame drops
Solutions:

  • Monitor ground trace frequency (should be once per frame max)
  • Check GameplayTagPropertyMap size (avoid excessive mappings)
  • Verify component references are cached (no searches per frame)
  • Use stat anim to identify bottlenecks

Development Tools

Blueprint Debugging

blueprint
# Check binding status
Event Blueprint Update Animation
├── Is Ability System Bound?
│   ├── True: Process normally
│   └── False: Print "ASC Not Bound"

# Monitor ground information  
├── Get Ground Info
│   └── Print Ground Distance

# Verify tag mappings
└── For each mapped property
    └── Print property name and value

Runtime Validation

cpp
// In custom NativeUpdateAnimation override
void UMyAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
    Super::NativeUpdateAnimation(DeltaSeconds);
    
    // Debug ASC binding
    if (!bIsAbilitySystemBound)
    {
        UE_LOG(LogTemp, Warning, TEXT("ASC not bound - Retry: %s, Waiting: %s"), 
               bShouldRetryASCBinding ? TEXT("True") : TEXT("False"),
               bIsWaitingForAbilitySystemDelegate ? TEXT("True") : TEXT("False"));
    }
    
    // Validate ground distance
    if (GroundDistance < -1.0f)
    {
        UE_LOG(LogTemp, Warning, TEXT("Invalid ground distance: %f"), GroundDistance);
    }
}

Performance Monitoring

console
# Monitor animation performance
stat startfile
stat anim
stat game
# ... play/test ...
stat stopfile

# Check frame timing
stat unit
stat fps

# Memory usage
stat memory
memreport

Motion - Advanced First Person Character Controller