언리얼 5

230905 애니메이션, 리로드 노티파이 / 파티클 이펙트 / Effect_Base

슬뷔 2023. 9. 9. 02:28

애니메이션 알림(Animation Notification)

걷거나 달리는 애니메이션에서의 발소리와 같은 사운드나 파티클 스폰 및 기타 유형

https://docs.unrealengine.com/5.0/ko/animation-notifies-in-unreal-engine/

 

애니메이션 노티파이

애니메이션 노티파이를 사용하여 애니메이션 시퀀스에 동기화된 이벤트를 전송하고 수신합니다.

docs.unrealengine.com

파티클 이펙트

파티클 이펙트(Particle Effect) 노티파이는 루프가 돌지 않는 파티클 시스템을 스폰하고 재생하는 데 사용됩니다.

// AniNotify_ + 노티파이 이름 으로 함수명을 구성할 것, UFUNCTION() 매크로 반드시 붙일 것
UFUNCTION()
void AnimNotify_FireStart();

UFUNCTION()
void AnimNotify_FireEnd(); 



void UAnimInstance_Base::AnimNotify_FireStart()
{
LOG(Player, Warning, TEXT("FireStart Notify Called"));
FireAnim = true;
}

void UAnimInstance_Base::AnimNotify_FireEnd()
{
LOG(Player, Warning, TEXT("FireEnd Notify Called"));
FireAnim = false;

if (!Character->IsFire)
{
Montage_Stop(0.2f);
}

마우스 왼쪽 키를 누르면 LOG(Player, Warning, TEXT("FireStart Notify Called")) 가 호출 되고, 떼면 LOG(Player, Warning, TEXT("FireEnd Notify Called")) 가 호출 된다.

리로드 노티파이 생성

void UAnimInstance_Base::AnimNotify_FireEnd()
{
	if (Character->IsReload)
	{
		Montage_Play(Character->GetFireMontage().LoadSynchronous());
		Montage_JumpToSection(FName(TEXT("Reload")));		
	}
	else if (!Character->IsFire)
	{
		Montage_Stop(0.2f);
	}	
}

void UAnimInstance_Base::AnimNotify_ReloadEnd()
{
	Character->IsReload = false;
}
void ACharacter_Base::Fire(const FInputActionInstance& _Instance)
{	
	bool bToggle = _Instance.GetValue().Get<bool>();

	if (!IsValid(GetMesh()->GetAnimInstance()) || FireMontage.IsNull())
	{		
		return;
	}
	
	if (bToggle && !IsReload)
	{		
		GetMesh()->GetAnimInstance()->Montage_Play(FireMontage.LoadSynchronous(), 2.f);
		GetMesh()->GetAnimInstance()->Montage_JumpToSection(FName("Fire"), FireMontage.LoadSynchronous());
		IsFire = true;
	}
	else
	{		
		IsFire = false;
	}
}

void ACharacter_Base::Reload(const FInputActionInstance& _Instance)
{
	IsReload = true;
}

Animnotify Blueprint

BPC_Effect 생성

Effect_Base.h / Effect_Base.cpp 생성

#include "Particles/ParticleSystemComponent.h"

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Effect_Base.generated.h"

UCLASS()
class UNREAL_3TH_API AEffect_Base : public AActor
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
	UParticleSystemComponent* m_PSC;

public:	
	// Sets default values for this actor's properties
	AEffect_Base();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

};
#include "Effect_Base.h"

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

	m_PSC = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("ParticleSystemComponent"));
	SetRootComponent(m_PSC);
}

// Called when the game starts or when spawned
void AEffect_Base::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AEffect_Base::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

 

Niagara 모듈 사용법

https://www.funsuperman.com/104

 

[언리얼 엔진] 나이아가라 시작하기

나이아가라 VFX 시스템 나이아가라 VFX 시스템 (Niagara VFX System) 은 언리얼 엔진(Unreal Engine) 내부에서 비주얼 이펙트를 생성하고 조정하는 데 사용하는 툴이다. 나이아가라 이전에는 캐스케이드(casc

www.funsuperman.com

 

Niagara 모듈을 쓰기위해서 Build.cs 에 Niagara 모듈 추가