Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

UnrealEngineer

[ UnrealEngine5 ] 캐릭터 애니메이션 본문

언리얼엔진5

[ UnrealEngine5 ] 캐릭터 애니메이션

UnrealEngineer 2024. 8. 19. 14:35

1. BCAnimInstance라는 이름의 AnimInstance 클래스를 생성

2. AnimationBlueprint 생성 [ Skeleton과 상속 클래스 설정 ]

 

3. 애님인스턴스와 소유하고 있는 액터는 상호참조가 가능하다.

AnimInstance

Event

1. NativeInitializeAnimation() : 애님인스턴스 클래스가 처음 생성될때 한번 호출

2. NativeUpdateAnimation() : 매 틱마다 계속 호출

 

AnimGraph

- State Alias 기능을 활용

 

 

4. 애님인스턴스 클래스

#pragma once

#include "CoreMinimal.h"
#include "Animation/AnimInstance.h"
#include "BCAnimInstance.generated.h"

UCLASS()
class BIKINICITY_API UBCAnimInstance : public UAnimInstance
{
	GENERATED_BODY()
	
public:

	UBCAnimInstance();

	virtual void NativeInitializeAnimation() override;

	virtual void NativeUpdateAnimation(float DeltaSeconds) override;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	TObjectPtr<class ACharacter> OwnerCharacter;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	TObjectPtr<class UCharacterMovementComponent> OwnerMovement;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	FVector OwnerVelocity;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	float OwnerGroundSpeed;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	uint8 bIsIdle : 1;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	float MovingThreshould;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	uint8 bIsFalling : 1;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	uint8 bIsJumping : 1;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Chracter)
	float JumpingThreshould;
};

 

#include "BCAnimInstance.h"

#include "GameFramework/Character.h"
#include "GameFramework/CharacterMovementComponent.h"

UBCAnimInstance::UBCAnimInstance()
{
	MovingThreshould = 3.0f;
	JumpingThreshould = 100.0f;
}

void UBCAnimInstance::NativeInitializeAnimation()
{
	Super::NativeInitializeAnimation();

	OwnerCharacter = Cast<ACharacter>(GetOwningActor());
	if (OwnerCharacter)
	{
		OwnerMovement = OwnerCharacter->GetCharacterMovement();
	}
}

void UBCAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
	Super::NativeUpdateAnimation(DeltaSeconds);

	if (OwnerMovement)
	{
		OwnerVelocity = OwnerMovement->Velocity;

		// z값을 제외한 지면의 속력
		OwnerGroundSpeed = OwnerVelocity.Size2D();

		bIsIdle = OwnerGroundSpeed < MovingThreshould;

		bIsFalling = OwnerMovement->IsFalling();

		bIsJumping = bIsFalling & (OwnerVelocity.Z > JumpingThreshould);
	}
}

 

5. 애니메이션 블루프린트 설정

Locomotion 캐시로 설정 BlendSpace1D로 Idle/Walk/Run 구성
Jump Alias 생성 Jump보다 늦게 실행되어야 함으로 PriorityOrder를 2로 설정