Course contentsShow
← Unreal Engine Game Development
Lesson 238 of 8804. Advanced Input and PhysicsFree lesson

Synchronizing Input Events with Animation Montages

You will utilize input triggers to fire animation notifies, ensuring gameplay actions align perfectly with character movement and visual feedback.

In this lesson, you will learn how to bridge the gap between user input and animation playback by using Animation Notifies (AnimNotifies) to ensure your character’s gameplay logic triggers exactly when the visual movement occurs.

The Problem: Timing

When you bind an InputAction to a function—like PerformAttack()—the logic often executes instantly. However, a sword swing animation takes time to play. If your "damage" logic executes the moment the player presses a button, the player hits the enemy before the sword even moves. We need a way to link the high-level input action to a specific frame within the animation timeline.

Bridging with AnimNotifies

Instead of handling damage inside the Input Action’s callback, use your input event to trigger the Animation Montage. Then, inside the Animation Montage editor, you place an AnimNotify at the precise frame where the weapon impact occurs.

  1. Input Stage: The InputAction triggers PlayAnimMontage.
  2. Animation Stage: The animation plays until it hits the AnimNotify.
  3. Execution Stage: Your Character class (or AnimInstance) catches the Notify and executes the gameplay logic (like ApplyDamage).

Implementation Concept

In your C++ character class, you define a function that responds to the notify. It is often best to keep this logic clean by binding it to the Animation Montage's internal event system:

// In your Character's function bound to the Input Action
void AMyCharacter::HandleAttackInput()
{
    if (AttackMontage)
    {
        PlayAnimMontage(AttackMontage);
    }
}

// In the Animation Notify event (or via an AnimNotifyState class)
void AMyCharacter::OnAttackHitNotify()
{
    // Now trigger damage logic here, perfectly synced with the frame
    PerformMeleeOverlapCheck();
}

By decoupling the input from the logic and using the animation itself as the "trigger," you create gameplay that feels tactile and responsive. The player presses the button, the animation starts, and the world reacts only when the weapon makes contact.

Key Takeaway: Never trigger gameplay-critical logic directly from an input binding if it depends on character movement; instead, trigger a Montage and use AnimNotifies to fire the logic at the perfect frame.