애니메이션 몽타주를 설정해 보자
캐릭터의 Mesh에 들어가 본다
애셋생성 -> 애님 몽타주 클릭
몽타주 생성
애니메이션 편집기라 보면된다.
몽타주를 적용해보자
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction(TEXT("Jump"), EInputEvent::IE_Pressed, this, &AMyCharacter::Jump);
PlayerInputComponent->BindAction(TEXT("Attack"), EInputEvent::IE_Pressed, this, &AMyCharacter::Attack);
// ...
void AMyCharacter::Attack()
{
auto AnimInstance = Cast<UMyAnimInstance>(GetMesh()->GetAnimInstance());
if (AnimInstance)
{
AnimInstance->PlayAttackMontage();
}
}
UCLASS()
class TESTUNREALENGINE_API UMyAnimInstance : public UAnimInstance
{
// ...
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Pawn, Meta = (AllowPrivateAccess = true))
UAnimMontage* AttackMontage;
};
UMyAnimInstance::UMyAnimInstance()
{
static ConstructorHelpers::FObjectFinder<UAnimMontage> AM(TEXT("AnimMontage'/Game/Animations/Greystone_Skeleton_Montage.Greystone_Skeleton_Montage'"));
if (AM.Succeeded())
{
AttackMontage = AM.Object;
}
}
// ...
void UMyAnimInstance::PlayAttackMontage()
{
if (!Montage_IsPlaying(AttackMontage))
{
Montage_Play(AttackMontage, 1.f);
}
}