728x90

0. 서문

C++ 함수의 동작 중 Blueprint의 이벤트를 발생시키는 방법을 찾는 과정에서 Delegate와 UFUNCTION을 사용하여 C++과 Blueprint를 연결하는 방법을 발견했습니다.

특히, C++에서 'BlueprintNativeEvent'와 'BlueprintImplementableEvent'를 사용하는 과정을 정리해 보았습니다.

1. 함수 생성

 

1.1. 블루프린트 구현가능 이벤트 생성 (BlueprintImplementableEvent)

1.1.1. 함수 생성 방법

public:
	UFUNCTION(BlueprintImplementableEvent)
	void AttackDone();

해당 방법의 경우, 함수의 구현 없이 활용한다.

1.1.2. Blueprint 활용 방법

Event 혹은 Function 동작이 필요한 경우 호출을 통해 활용이 가능하다.

- 예시: Attack Function 동작 중간, AttackDone() 함수 동작이 필요한 경우

void Attack()
{
	// ... 코드 생략
	UE_LOG(LogTemp, Display, TEXT("AttackDone Start!"));
	AttackDone();
	UE_LOG(LogTemp, Display, TEXT("AttackDone Finish!"));
}

1.1.2.1. 단순 호출

1.1.2.2. 호출 간 Async 동작이 포함되는 경우

 

1.1.3. 오류 발생 경우

만일, 다음과 같이 함수 내부를 구현하는 경우, 오류가 발생한다.

void APlayerBase::AttackDone()
{
	UE_LOG(LogTemp, Warning, TEXT("AttackDone Event!"));
}

 

 

1.2. 블루프린트 네이티브 이벤트 생성 (BlueprintNativeEvent)

1.2.1. 함수 생성 방법

public:
	UFUNCTION(BlueprintNativeEvent)
	void AttackDone();
	virtual void AttackDone_Implementation(); // 해당 코드의 유무와 무관하게 컴파일 및 동작 가능
void AttackDone_Implementation()
{
	UE_LOG(LogTemp, Warning, TEXT("AttackDone Implementation Event!"));
}

함수의 구현이 필요한 경우, '_Implementation'을 함수 끝에 추가하는 경우 사용이 가능하다.

이때, 'virtual void AttackDone_Implementation()' 선언이 header에서 생략된 경우에도 동일하게 동작한다.

 

1.2.2. Blueprint 활용 방법

- 예시: Attack Function 동작 간, AttackDone() 함수 호출

void Attack()
{
	// ... 코드 생략
	UE_LOG(LogTemp, Display, TEXT("AttackDone Start!"));
	AttackDone();
	UE_LOG(LogTemp, Display, TEXT("AttackDone Finish!"));
}

1.2.2.1. Override가 없는 경우

 

 

1.2.2.2. Override(Event 생성)를 적용한 경우

 

1.2.2.3. Override(Event 생성) 후, 부모 클래스의 Attack Done을 호출 한 경우

 

 

 

2. 참고자료

https://forums.unrealengine.com/t/i-want-to-add-component-event-in-c/673416

 

I want to add component event in c++

Hi I’m converting Blueprint to c++ and i got Some problem. In Blueprint, I could call component event in actor easley but in c++ I dont know how to call it. how can i call component event in c++ Actor that owns it?

forums.unrealengine.com

https://forums.unrealengine.com/t/how-do-i-create-a-custom-event-in-c/286942/16

 

How do I create a Custom Event in C++?

Hi! Sorry to hear you’re having trouble with this - Are you trying to do BlueprintImplementableEvent or BlueprintNativeEvent? The first one will only have behavior written in Blueprints, but the second one can also have C++ behavior. If you want a Bluepr

forums.unrealengine.com

https://medium.com/@rdolivo/unreal-engine-how-to-declare-a-custom-event-in-c-313cc5dd975a

 

Unreal Engine: How to declare a custom event in C++

This tutorial will show you how to declare a custom event in C++ and expose it to Blueprints.

medium.com

 

https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/Events/

 

Events

Delegates that can be bound to multiple functions and execute them all at once.

docs.unrealengine.com

https://forums.unrealengine.com/t/why-cant-i-tag-a-delegate-created-with-declare-event-as-a-uproperty/343501

 

Why can't I tag a delegate created with DECLARE_EVENT as a UPROPERTY

I have a class I want to add some Events to that are exposed to Blueprints. It looks something like this: UCLASS(Blueprintable, BlueprintType) class MONSTERHOCKEY_API APeriodManager : public AInfo { GENERATED_BODY() ... public: DECLARE_EVENT(APeriodManager

forums.unrealengine.com

https://darkcatgame.tistory.com/66

 

UE4 C++ Delegate 정리 & 샘플 프로젝트

개인적으로 UE4 C++에서 Delegate를 사용할 때 처음에 굉장히 에러를 많이 겪었습니다, 그래서 이번 포스팅은 UE4 C++에서 Delegate를 사용하는 방법에 대해 정리하고 샘플프로젝트도 만들었습니다. https

darkcatgame.tistory.com

https://woo-dev.tistory.com/331

 

BlueprintNativeEvent - UFUNCTION 매크로 지정자

UFUNCTION 매크로에 BlueprintNativeEvent 라는 지정자를 넣어줄 수 있다. 이 지정자의 의도는 기본적으로 우리가 C++에서 함수 구현을 할 것이지만, 필요하다면 블루프린트에서 함수 재정의를 할 수 있도

woo-dev.tistory.com

 

https://docs.unrealengine.com/4.27/ko/ProgrammingAndScripting/Blueprints/TechnicalGuide/ExtendingBlueprints/

 

블루프린트에 게임플레이 요소 노출시키기

게임플레이 요소를 블루프린트에 노출시키는 게임플레이 프로그래머를 위한 기술 안내서입니다.

docs.unrealengine.com

 

+ Recent posts