Animation Blueprint는 AnimInstance를 상속받은 블루프린트 클래스이다
- AnimInstance를 상속받은 C++ 클래스 생성
public:
URAnimInstance(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
public:
virtual void NativeInitializeAnimation() override;
virtual void NativeUpdateAnimation(float DeltaSeconds) override;
protected:
UPROPERTY(BlueprintReadOnly)
TObjectPtr<class ARPlayer> Character;
UPROPERTY(BlueprintReadOnly)
TObjectPtr<class UCharacterMovementComponent> MovementComponent;
protected:
UPROPERTY(BlueprintReadOnly)
FVector Velocity = FVector::ZeroVector;
UPROPERTY(BlueprintReadOnly)
float GroundSpeed = 0.f;
UPROPERTY(BlueprintReadOnly)
bool bShouldMove = false;
UPROPERTY(BlueprintReadOnly)
bool bIsFalling = false;
void URAnimInstance::NativeInitializeAnimation()
{
Super::NativeInitializeAnimation();
Character = Cast<ARPlayer>(TryGetPawnOwner());
if(Character)
{
MovementComponent = Character->GetCharacterMovement();
}
}
void URAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
if(Character==nullptr)
return;
if(MovementComponent==nullptr)
return;
Velocity = MovementComponent->Velocity;
GroundSpeed = Velocity.Size2D();
bShouldMove = (GroundSpeed > 3.f && MovementComponent->GetCurrentAcceleration() != FVector::ZeroVector);
bIsFalling = MovementComponent->IsFalling();
}
- NativeInitializeAnimation: BeginPlay처럼 딱 한 번 초기화하는 함수
- NativeUpdateAnimation: Tick처럼 매 프레임마다 실행하는 함수
- ABP_Manny의 블루프린트를 참고하여 그대로 만들어주면 된다