11 - Animation
A UAnimInstance subclass that computes blend-space inputs (speed) and drives them every tick via NativeUpdateAnimation.
Full source
include "CoreMinimal.h"
include "Animation/AnimInstance.h"
include "GameFramework/Character.h"
uclass AExampleAnim : UAnimInstance meta: api=EXAMPLES_API
{
prop public float Speed EditAnywhere BlueprintReadWrite category="Anim" default=0.0f
prop public bool bIsMoving EditAnywhere BlueprintReadWrite category="Anim" default=false
method public virtual void NativeUpdateAnimation(float DeltaSeconds) override {
Super::NativeUpdateAnimation(DeltaSeconds);
APawn* MyPawn = TryGetPawnOwner();
if (MyPawn)
{
Speed = MyPawn->GetVelocity().Size();
bIsMoving = Speed > 10.0f;
}
}
}
Line by line
uclass AExampleAnim : UAnimInstance- an animation blueprint's backing C++ class.prop public float Speed ... BlueprintReadWrite- a blend-space input: the animation graph reads this to pick walk/run/jog.prop public bool bIsMoving ... BlueprintReadWrite- a bool for a "moving" state machine condition.method public virtual void NativeUpdateAnimation(float DeltaSeconds) override- the per-frame animation update (the C++ equivalent of the event graph's Event Update Animation).TryGetPawnOwner()- the owning pawn.Speed = MyPawn->GetVelocity().Size();- magnitude of velocity.bIsMoving = Speed > 10.0f;- moving flag with a threshold.
Using it
In the Animation Blueprint, these become variable nodes you can feed into a Blend Space 1D (or use in state machine transition rules). Because they're BlueprintReadWrite, they show up in the AnimGraph as regular scalar/bool vars.
Next: 12 - Audio.