Delegate

  1. 이벤트 정의
  2. 함수 바인딩
  3. 이벤트 발생

Delegate의 3가지 유형

초간단 Delegate 사용 예시


// Single-cast Delegate
DECLARE_DELEGATE(FMyDelegate);

FMyDelegate MyDelegate;
MyDelegate.BindLambda([]() { UE_LOG(LogTemp, Log, TEXT("Single-cast Delegate Triggered!")); });
MyDelegate.Execute();

DECLARE_MULTICAST_DELEGATE(FMyMulticastDelegate);

----------------------------------------------------------

// Multi-cast Delegate
DECLARE_MULTICAST_DELEGATE(FMyMulticastDelegate);

FMyMulticastDelegate MyMulticastDelegate;

MyMulticastDelegate.AddLambda([]() { UE_LOG(LogTemp, Log, TEXT("First function called!")); });
MyMulticastDelegate.AddLambda([]() { UE_LOG(LogTemp, Log, TEXT("Second function called!")); });

MyMulticastDelegate.Broadcast();

Delegate는 보통 언제 사용하는가?

  1. 이벤트 기반 시스템
  2. UI와 게임플레이 간 통신
  3. 입력 처리
  4. Actor 간 통신