$npx -y skills add quodsoler/unreal-engine-skills --skill ue-animation-systemUse this skill when working with Unreal Engine animation: AnimInstance, montage playback, blend space, state machine, anim notify, IK, AnimGraph, skeletal mesh, or linked anim graphs. See references/anim-notify-reference.md for notify patterns and references/locomotion-setup.md f
| 1 | # UE Animation System |
| 2 | |
| 3 | You are an expert in Unreal Engine's animation system. |
| 4 | |
| 5 | ## Context Check |
| 6 | |
| 7 | Read `.agents/ue-project-context.md` first. Note which plugins are enabled |
| 8 | (Control Rig, Motion Matching, Full Body IK), whether GAS is in use, and the |
| 9 | skeleton/character hierarchy. |
| 10 | |
| 11 | ## Information to Gather |
| 12 | |
| 13 | 1. What animation need? (locomotion, ability, cinematic, IK, procedural) |
| 14 | 2. C++ only, Blueprint only, or mixed? |
| 15 | 3. Does the character use `ACharacter` with an existing `USkeletalMeshComponent`? |
| 16 | 4. Is GAS active? (affects montage replication) |
| 17 | 5. Multiplayer? (determines replication strategy) |
| 18 | 6. Does the project use modular linked anim layers? |
| 19 | |
| 20 | --- |
| 21 | |
| 22 | ## Architecture |
| 23 | |
| 24 | ``` |
| 25 | ACharacter / AActor |
| 26 | └── USkeletalMeshComponent |
| 27 | └── UAnimInstance subclass |
| 28 | ├── NativeInitializeAnimation() [setup, game thread] |
| 29 | ├── NativeUpdateAnimation(float dt) [game thread] |
| 30 | ├── NativeThreadSafeUpdateAnimation(dt) [worker thread] |
| 31 | ├── FAnimInstanceProxy [worker thread eval] |
| 32 | └── Montage API / Linked Layers |
| 33 | ``` |
| 34 | |
| 35 | Animation updates run in two phases. Game thread: `NativeUpdateAnimation` — |
| 36 | safe to read gameplay state. Worker thread: blend tree evaluation. Write all |
| 37 | shared state as `UPROPERTY() Transient` members in `NativeUpdateAnimation`; |
| 38 | read those cached values in `NativeThreadSafeUpdateAnimation`. |
| 39 | |
| 40 | --- |
| 41 | |
| 42 | ## AnimInstance |
| 43 | |
| 44 | ### Subclass Pattern |
| 45 | |
| 46 | ```cpp |
| 47 | // MyAnimInstance.h |
| 48 | UCLASS() |
| 49 | class MYGAME_API UMyAnimInstance : public UAnimInstance |
| 50 | { |
| 51 | GENERATED_BODY() |
| 52 | |
| 53 | virtual void NativeInitializeAnimation() override; |
| 54 | virtual void NativeUpdateAnimation(float DeltaSeconds) override; |
| 55 | virtual void NativeThreadSafeUpdateAnimation(float DeltaSeconds) override; |
| 56 | |
| 57 | protected: |
| 58 | UPROPERTY(Transient) TObjectPtr<ACharacter> OwningCharacter; |
| 59 | UPROPERTY(Transient) TObjectPtr<UCharacterMovementComponent> MovementComp; |
| 60 | |
| 61 | UPROPERTY(Transient, BlueprintReadOnly, Category="Locomotion") |
| 62 | float Speed = 0.f; |
| 63 | |
| 64 | UPROPERTY(Transient, BlueprintReadOnly, Category="Locomotion") |
| 65 | float Direction = 0.f; |
| 66 | |
| 67 | UPROPERTY(Transient, BlueprintReadOnly, Category="Locomotion") |
| 68 | bool bIsInAir = false; |
| 69 | }; |
| 70 | ``` |
| 71 | |
| 72 | ```cpp |
| 73 | // MyAnimInstance.cpp |
| 74 | void UMyAnimInstance::NativeInitializeAnimation() |
| 75 | { |
| 76 | Super::NativeInitializeAnimation(); // ALWAYS call super |
| 77 | OwningCharacter = Cast<ACharacter>(TryGetPawnOwner()); |
| 78 | if (OwningCharacter) |
| 79 | MovementComp = OwningCharacter->GetCharacterMovement(); |
| 80 | } |
| 81 | |
| 82 | void UMyAnimInstance::NativeUpdateAnimation(float DeltaSeconds) |
| 83 | { |
| 84 | Super::NativeUpdateAnimation(DeltaSeconds); |
| 85 | if (!OwningCharacter || !MovementComp) return; |
| 86 | |
| 87 | const FVector Velocity = MovementComp->Velocity; |
| 88 | Speed = Velocity.Size2D(); |
| 89 | bIsInAir = MovementComp->IsFalling(); |
| 90 | |
| 91 | if (Speed > 3.f) |
| 92 | { |
| 93 | const FRotator ActorRot = OwningCharacter->GetActorRotation(); |
| 94 | const FRotator VelocityRot = Velocity.ToOrientationRotator(); |
| 95 | Direction = UKismetMathLibrary::NormalizedDeltaRotator( |
| 96 | VelocityRot, ActorRot).Yaw; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void UMyAnimInstance::NativeThreadSafeUpdateAnimation(float DeltaSeconds) |
| 101 | { |
| 102 | Super::NativeThreadSafeUpdateAnimation(DeltaSeconds); |
| 103 | // Only read UPROPERTY members written in NativeUpdateAnimation above. |
| 104 | // Do NOT call any UObject functions not marked BlueprintThreadSafe. |
| 105 | } |
| 106 | ``` |
| 107 | |
| 108 | ### FAnimInstanceProxy — Thread-Safe Access |
| 109 | |
| 110 | Heavy animation logic can run on worker threads via |
| 111 | `NativeThreadSafeUpdateAnimation`. Access shared data through the proxy: |
| 112 | |
| 113 | ```cpp |
| 114 | void UMyAnimInstance::NativeThreadSafeUpdateAnimation(float DeltaSeconds) |
| 115 | { |
| 116 | FMyAnimInstanceProxy& Proxy = GetProxyOnAnyThread<FMyAnimInstanceProxy>(); |
| 117 | Proxy.Speed = Proxy.Velocity.Size(); |
| 118 | Proxy.bIsFalling = Proxy.MovementMode == EMovementMode::MOVE_Falling; |
| 119 | } |
| 120 | ``` |
| 121 | |
| 122 | ```cpp |
| 123 | // FAnimInstanceProxy declaration — worker thread data container |
| 124 | USTRUCT() |
| 125 | struct FMyAnimInstanceProxy : public FAnimInstanceProxy |
| 126 | { |
| 127 | GENERATED_BODY() |
| 128 | FMyAnimInstanceProxy() = default; |
| 129 | explicit FMyAnimInstanceProxy(UAnimInstance* Instance) : FAnimInstanceProxy(Instance) {} |
| 130 | |
| 131 | float Speed = 0.f; |
| 132 | FVector Velocity = FVector::ZeroVector; |
| 133 | TEnumAsByte<EMovementMode> MovementMode = MOVE_None; |
| 134 | |
| 135 | virtual void PreUpdate(UAnimInstance* AnimInstance, float DeltaSeconds) override; |
| 136 | virtual void Update(float DeltaSeconds) override; |
| 137 | }; |
| 138 | |
| 139 | // In UMyAnimInstance: override CreateAnimInstanceProxy to return your proxy |
| 140 | virtual FAnimInstanceProxy* CreateAnimInstanceProxy() override |
| 141 | { return new FMyAnimInstanceProxy |