애니메이션 파일로 재생하는 방법

void AABPawn::BeginPlay()
{
    Super::BeginPlay();
    Mesh->SetAnimationMode(EAnimationMode::AnimationSingleNode);
    UAnimationAsset* AnimAsset = LoadObject<UAnimationAsset>(nullptr,
        TEXT("/Game/Book/ANIM/WarriorRun.WarriorRun"));

    if (AnimAsset != nullptr)
    {
        Mesh->PlayAnimation(AnimAsset, true);
    }
}

애니메이션 블루프린트를 이용해서 재생하는 방법 생성자에서 해야함. beginplay에서 할려고 뻥남

AABPawn::AABPawn()
{
    // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;


    Capsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CAPSULE"));
    Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MESH"));
    Movement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("MOVEMENT"));
    SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SPRINGARM"));
    Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("CAMERA"));

    RootComponent = Capsule;
    Mesh->SetupAttachment(Capsule);
    SpringArm->SetupAttachment(Capsule);
    Camera->SetupAttachment(SpringArm);

    Capsule->SetCapsuleHalfHeight(88.0f);
    Capsule->SetCapsuleRadius(34.0f);
    Mesh->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, -88.0f),FRotator(0.0f,-90.0f,0.0f));
    SpringArm->TargetArmLength = 400.0f;
    SpringArm->SetRelativeRotation(FRotator(-15.0f,0.0f,0.0f));

    static ConstructorHelpers::FObjectFinder<USkeletalMesh>
        SK_CARDBOARD(TEXT("/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Cardboard.SK_CharM_Cardboard"));

    if (SK_CARDBOARD.Succeeded())
    {
        Mesh->SetSkeletalMesh(SK_CARDBOARD.Object);
    }

//코드 추가됨
    Mesh->SetAnimationMode(EAnimationMode::AnimationBlueprint);
    static ConstructorHelpers::FClassFinder<UAnimInstance>  WARRIOR_ANIM(TEXT("/Game/Book/ANIM/WarriorAnimBluePrint.WarriorAnimBluePrint_C"));

    if (WARRIOR_ANIM.Succeeded())
    {
        Mesh->SetAnimInstanceClass(WARRIOR_ANIM.Class);
    }

}

+ Recent posts