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
- Create or open your Animation Blueprint
- In Class Settings, set Parent Class to
MotionAnimInstance - Configure the
GameplayTagPropertyMapin Class Defaults - Map gameplay tags to animation blueprint variables
- The instance will auto-bind to the character's Ability System Component
- Ground information will be automatically calculated and cached
- 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
| Function | Parameters | Return Type | Description |
|---|---|---|---|
NativeInitializeAnimation() | None | void | Override to initialize custom animation systems |
NativeUninitializeAnimation() | None | void | Override to cleanup custom animation systems |
NativeUpdateAnimation() | float DeltaSeconds | void | Override to add custom animation update logic |
InitializeWithAbilitySystem() | UAbilitySystemComponent* ASC | void | Initialize the animation instance with AbilitySystemComponent |
Ground Detection Functions
| Function | Parameters | Return Type | Description |
|---|---|---|---|
GetGroundInfo() | None | FMotionGroundInfo | Calculate and cache ground distance information |
ASC Integration Functions
| Function | Parameters | Description |
|---|---|---|
OnAbilitySystemAvailable() | UAbilitySystemComponent* ASC | Called when ASC becomes available via delegate |
Editor Validation Functions
| Function | Parameters | Return Type | Description |
|---|---|---|---|
IsDataValid() | FDataValidationContext& Context | EDataValidationResult | Validate animation data and tag mappings (Editor only) |
Configuration Properties
Gameplay Tag Property Mapping
| Property | Type | Description |
|---|---|---|
| GameplayTagPropertyMap | FGameplayTagBlueprintPropertyMap | Maps gameplay tags to Blueprint properties for automatic updates |
Animation State Properties
| Property | Type | Category | Description |
|---|---|---|---|
| GroundDistance | float | Character State Data | Distance to ground below character (cached per frame) |
| bIsAbilitySystemBound | bool | Motion Animation | Whether successfully bound to AbilitySystemComponent |
Ground Information Structure
FMotionGroundInfo provides comprehensive ground detection:
| Property | Type | Description |
|---|---|---|
| GroundHitResult | FHitResult | Complete hit information from ground trace |
| GroundDistance | float | Distance to ground (-1.0 if no ground detected) |
| LastUpdateFrame | uint32 | Frame number when last updated for caching |
Read-Only State Properties
Cached Component References
| Property | Type | Description |
|---|---|---|
| CachedCharacter | ACharacter* | Cached reference to the owning character |
| CachedCharacterMovement | UCharacterMovementComponent* | Cached reference to character movement component |
| CachedCapsuleComponent | UCapsuleComponent* | Cached reference to capsule component |
| CachedAbilitySystemComponent | UAbilitySystemComponent* | Cached reference to the ASC |
Internal State Tracking
| Property | Type | Description |
|---|---|---|
| CachedGroundInfo | FMotionGroundInfo | Cached ground information to avoid redundant calculations |
| bIsAbilitySystemBound | bool | Flag tracking successful ASC binding |
| bIsWaitingForAbilitySystemDelegate | bool | Flag tracking delegate callback waiting state |
| bShouldRetryASCBinding | bool | Flag tracking need to retry ASC binding |
Gameplay Tag Property Mapping Setup
In the Animation Blueprint's Class Defaults:
- Find
GameplayTagPropertyMap - Add entries for each tag-to-property mapping:
- Tag:
Motion.State.Walking - Property Name:
bIsWalking - Property Type: Boolean
- Tag:
Common Motion Tag Mappings
| Gameplay Tag | Property Name | Type | Usage |
|---|---|---|---|
| Motion.State.Walking | bIsWalking | Bool | Walking animation state |
| Motion.State.Sprinting | bIsSprinting | Bool | Sprint animation state |
| Motion.State.Crouching | bIsCrouching | Bool | Crouch animation state |
| Motion.State.Jumping | bIsJumping | Bool | Jump/fall animation state |
| Motion.State.WantsToSprint | bWantsToSprint | Bool | Sprint intention |
| Motion.State.WantsToCrouch | bWantsToCrouch | Bool | Crouch intention |
| Motion.State.InAir | bIsInAir | Bool | Airborne state |
| Motion.State.OnGround | bIsOnGround | Bool | Grounded state |
Advanced Ground Detection System
Sophisticated ground information with frame-based caching:
// 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
// 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 animationsAutomatic ASC Binding
The system handles ASC availability automatically:
- Attempts immediate binding on initialization
- If PlayerState not ready, registers delegate
- Retries binding when ASC becomes available
- Handles both client and server scenarios
Advanced Features
Intelligent ASC Binding System
Sophisticated binding mechanism with multiple fallback strategies:
// 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
// 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
| Variable | Type | Category | Description |
|---|---|---|---|
| GroundDistance | float | Character State Data | Current distance to ground |
| bIsAbilitySystemBound | bool | Motion Animation | ASC 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
# 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 ComponentCommon 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 > 100Blend 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:
# 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 gameCommon Issues and Solutions
Properties Not Updating
Problem: Gameplay tag properties not reflecting ASC state
Solutions:
// 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 runtimeASC 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:
// 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 issuesPerformance 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
# 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 valueRuntime Validation
// 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
# 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