TExcelTAD
Home › Unreal Engine 5 with C++ › Montages, Notifies, Control Rig & IK

Montages, Notifies, Control Rig & IK

State machines handle continuous movement. One-off actions — an attack, a reload, a dodge, a hit reaction — are played as Animation Montages: assets that wrap one or more animations, split them into named sections, carry notifies (events at points in time) and play in a slot of the AnimGraph, layered over locomotion.

Playing a montage

cpp
// ArenaCharacter.h
UPROPERTY(EditDefaultsOnly, Category = "Combat")
TObjectPtr<UAnimMontage> AttackMontage;

// ArenaCharacter.cpp
void AArenaCharacter::StartAttack()
{
    if (UAnimInstance* Anim = GetMesh()->GetAnimInstance(); Anim && AttackMontage)
    {
        if (Anim->Montage_IsPlaying(AttackMontage)) return;     // no restarting mid-swing

        PlayAnimMontage(AttackMontage, /*Rate*/ 1.f, /*Section*/ FName(TEXT("Swing1")));

        FOnMontageEnded Ended;
        Ended.BindUObject(this, &AArenaCharacter::OnAttackEnded);  // void OnAttackEnded(UAnimMontage*, bool bInterrupted)
        Anim->Montage_SetEndDelegate(Ended, AttackMontage);
    }
}

For the montage to be visible, the AnimGraph needs a Slot node (usually DefaultSlot, or an UpperBody slot inside a Layered blend per bone so the legs keep running). A montage that plays but doesn't show is almost always a missing slot.

Useful calls: Montage_JumpToSection, Montage_SetNextSection (combo chains), Montage_Stop(BlendOutTime, Montage), Montage_GetPosition. In GAS, abilities play montages with the PlayMontageAndWait ability task, which also handles networking.

Notifies

A notify fires an event at a point in the animation. A notify state has a begin, tick and end, covering a window.

Use Type
footstep sounds and dust built-in Play Sound / Play Niagara Effect notifies
"the sword can hit now" a notify state ANS_HitWindow: begin enables the weapon trace, end disables it
"a combo input is accepted now" a notify state ANS_ComboWindow
"spawn the projectile at the hand" a custom notify AN_Fire
cpp
// AN_Fire.h: a custom notify (UE 5.x signature with EventReference)
UCLASS()
class ARENA_API UAN_Fire : public UAnimNotify
{
    GENERATED_BODY()

public:
    virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation,
                        const FAnimNotifyEventReference& EventReference) override
    {
        Super::Notify(MeshComp, Animation, EventReference);
        if (AArenaCharacter* Owner = Cast<AArenaCharacter>(MeshComp->GetOwner()))
        {
            Owner->FireFromSocket(TEXT("hand_r"));
        }
    }
};

Notifies also fire in the editor's animation preview, where the owner is not your character: always cast and null-check. Also, a notify on an animation that is blended out early may never fire. For gameplay-critical events (damage), the notify-state window plus a fallback timeout is safer than a single point notify.

A model: a combo with sections and notify windows

cpp · try it yourself
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

struct Window { std::string Name; double Begin, End; };
struct Section { std::string Name; double Length; std::vector<Window> Windows; std::string Next; };

int main() {
    std::cout << std::fixed << std::setprecision(1);
    std::vector<Section> montage = {
        {"Swing1", 0.8, {{"HitWindow", 0.2, 0.4}, {"ComboWindow", 0.4, 0.7}}, "Swing2"},
        {"Swing2", 1.0, {{"HitWindow", 0.3, 0.5}, {"ComboWindow", 0.5, 0.8}}, "Finisher"},
        {"Finisher", 1.2, {{"HitWindow", 0.5, 0.8}}, ""},
    };
    std::vector<double> attackPresses = {0.1, 0.55, 1.0};   // the second press lands in Swing1's combo window

    const double dt = 0.1;
    size_t s = 0;
    double t = 0, sectionTime = 0;
    bool queued = false;
    size_t press = 1;                                        // the first press started the montage at t=0.1
    std::cout << "t=0.1 attack pressed: play section Swing1\n";
    t = 0.1;
    while (true) {
        t += dt; sectionTime += dt;
        const Section& sec = montage[s];
        for (const auto& w : sec.Windows) {
            if (std::abs(sectionTime - w.Begin) < 1e-6) std::cout << "t=" << t << " " << sec.Name << " " << w.Name << " begin\n";
            if (std::abs(sectionTime - w.End) < 1e-6) std::cout << "t=" << t << " " << sec.Name << " " << w.Name << " end\n";
        }
        if (press < attackPresses.size() && t >= attackPresses[press] - 1e-6) {
            bool inCombo = false;
            for (const auto& w : sec.Windows)
                if (w.Name == "ComboWindow" && sectionTime >= w.Begin - 1e-6 && sectionTime < w.End - 1e-6) inCombo = true;
            std::cout << "t=" << t << " attack pressed: " << (inCombo ? "queued " + sec.Next : "ignored (not in combo window)") << "\n";
            queued = queued || inCombo;
            press++;
        }
        if (sectionTime >= sec.Length - 1e-6) {
            if (queued && !sec.Next.empty()) {
                std::cout << "t=" << t << " Montage_JumpToSection " << sec.Next << "\n";
                s++; sectionTime = 0; queued = false;
            } else {
                std::cout << "t=" << t << " montage ended, OnMontageEnded(bInterrupted=false)\n";
                break;
            }
        }
    }
}
t=0.1 attack pressed: play section Swing1
t=0.3 Swing1 HitWindow begin
t=0.5 Swing1 HitWindow end
t=0.5 Swing1 ComboWindow begin
t=0.6 attack pressed: queued Swing2
t=0.8 Swing1 ComboWindow end
t=0.9 Montage_JumpToSection Swing2
t=1.0 attack pressed: ignored (not in combo window)
t=1.2 Swing2 HitWindow begin
t=1.4 Swing2 HitWindow end
t=1.4 Swing2 ComboWindow begin
t=1.7 Swing2 ComboWindow end
t=1.9 montage ended, OnMontageEnded(bInterrupted=false)

The third press at t = 1.0 arrived while Swing2 was outside its combo window, so the combo stopped after two swings. Moving that press later, into Swing2's window, would play the finisher.

Control Rig and IK

  • Control Rig is a node-based rigging system that runs in the AnimGraph (and in Sequencer). Use it for procedural adjustments: aiming the spine toward a target, foot placement on uneven ground, a hand reaching for a door handle.
  • IK (inverse kinematics) solves joint angles so a bone end reaches a target. Common nodes: Two Bone IK (arms, legs), FABRIK, Leg IK, and the IK Rig asset with IK Retargeter for moving animations between skeletons of different proportions (UE5's retargeting workflow).
  • Foot placement: trace down from each foot (the trace lesson!), raise or lower the foot to the hit point, and drop the pelvis by the larger offset. Control Rig and the Foot Placement node implement this.
  • Motion Matching (UE 5.4+, with the Pose Search plugin) picks animation frames from a database by matching the character's trajectory: a different approach to locomotion than state machines. Epic's Game Animation Sample project shows it.

Test yourself

A montage plays (Montage_IsPlaying is true) but the character doesn't move. What's the likely cause?

  1. The montage has no sections
  2. The AnimGraph has no Slot node for the montage's slot
  3. The montage is too short
  4. Notifies are disabled

Which tool fits 'the weapon can deal damage only between these frames'?

  1. A Blend Space
  2. An Anim Notify State window
  3. A Material Instance
  4. A state machine conduit

What does the IK Retargeter do?

  1. Compiles shaders
  2. Transfers animations between skeletons with different proportions
  3. Creates navigation meshes
  4. Replicates bones