본문 바로가기

언리얼엔진/ThirdPersonTemplete

AnimNotify

나이아그라에서 만든 효과를 애니메이션에서 트리거하게 해보겠다.

C++클래스를 만든다. 밑의 AnimNotifyState는 주기가 있는 트리거고 AnimNotify는 단발성이다

UAnimNotify 부모위를 F12를 눌러 notify(를 찾아 복사해준다. 뒤에 overrider를 붙여준다.

AnimNotifyShowFX.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Animation/AnimNotifies/AnimNotify.h"
#include "TPSPlayer.h"
#include "AnimNotifyShowFX.generated.h"

/**
 * 
 */
UCLASS()
class P231113_API UAnimNotifyShowFX : public UAnimNotify
{
	GENERATED_BODY()

	UPROPERTY()
	ATPSPlayer* tpsPlayer;
	virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, 
		const FAnimNotifyEventReference& EventReference) override;
};

AnimNotifyShowFX.cpp

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

void UAnimNotifyShowFX::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, 
	const FAnimNotifyEventReference& EventReference)
{
	tpsPlayer = Cast<ATPSPlayer>(MeshComp->GetOwner());
	if (tpsPlayer) {
		bool show = tpsPlayer->GetCharacterMovement()->IsFalling();
		tpsPlayer->ShowFX();
	}
}

TPSPlayer.cpp ShowFX() 완성

void ATPSPlayer::ShowFX()
{
	if (niagaraFX == nullptr)
	{
		niagaraFX = GetComponentByClass<UNiagaraComponent>();
	}
	
	bool show = GetCharacterMovement()->IsFalling();
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Magenta, FString::Printf(TEXT("AnimNotify %d"), (int)show));
	niagaraFX->SetVisibility(show);
	//GetMesh()->SetVisibility(!show);
}

LocoMachine JumpStart를 열고 Jump Animation을 열어준다.

 

그래프 위를 우클릭하면 노티파이 이름이 보여야 정상이다 만든  AnimNofityShowFX를 선택한다.

 

착지할때 같은 노티파이를 한번더 보내준다 isFalling을 체크해 나이아가라를 꺼준다.

BP_Attractor 액터를 만들어 노드에서 AttractorPos1을 블루포인터의 위치 지정해준다.

레벨에 끌어다 놓고 변수를 지정해준다.

'언리얼엔진 > ThirdPersonTemplete' 카테고리의 다른 글

Widget 머리에 달기  (0) 2023.12.04
스폰한 캐릭터 안움직이는 이유  (0) 2023.12.04
언리얼 Animation Montage  (0) 2023.11.14
캐릭터 메시 지정하기  (0) 2023.11.13
PBullet 발사체 만들기  (1) 2023.11.13