사용자 정의 델리게이트는 매우 유용하지만,다른 서드파티 클래스에 의해 외부 에서 브로드캐스트할 수 있다는 한계점이 있다 .
즉,Execute/Broadcast 메소드가 공개 적으로 액세스할 수 있다는 것이다 .
때로는 다른 클래스에 의해 외부에서 바인드는 할 수는 있지만 해당 클래스에 의해서만 브로드캐스트할 수 있는 델리게이트가 필요할 수 있다 .
이것이 이벤트의 주된 목적이다 .
AMyTriggerVolume.h
#pragma once
#include "CoreMinimal.h"
#include "Components/BoxComponent.h"
#include "GameFramework/Actor.h"
#include "MyTriggetrVolume.generated.h"
DECLARE_EVENT(AMyTriggetrVolume,FplayerEntered)
UCLASS()
class WILLIAM_API AMyTriggetrVolume : public AActor
{
GENERATED_BODY()
//UProperty
public:
UPROPERTY()
UBoxComponent* TriggerZone;
FplayerEntered OnPlayerEntered;
//UFUNCTION
public:
UFUNCTION()
virtual void NotifyActorBeginOverlap(AActor* OtherActor) override;
UFUNCTION()
virtual void NotifyActorEndOverlap(AActor* OtherActor) override;
public:
AMyTriggetrVolume();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
};
AMyTriggerVolume.cpp
#include "MyTriggetrVolume.h"
#include "GameModeBase_05.h"
#include "Kismet/GameplayStatics.h"
// Sets default values
AMyTriggetrVolume::AMyTriggetrVolume()
{
PrimaryActorTick.bCanEverTick = true;
TriggerZone = CreateDefaultSubobject<UBoxComponent>("TriggetZone");
TriggerZone->SetBoxExtent(FVector(200, 200, 10));
}
void AMyTriggetrVolume::BeginPlay()
{
Super::BeginPlay();
}
void AMyTriggetrVolume::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AMyTriggetrVolume::NotifyActorBeginOverlap(AActor* OtherActor)
{
Super::NotifyActorBeginOverlap(OtherActor);
OnPlayerEntered.Broadcast();
}
void AMyTriggetrVolume::NotifyActorEndOverlap(AActor* OtherActor)
{
}
ATirggetVolEventListener.h
#pragma once
#include "CoreMinimal.h"
#include "Components/PointLightComponent.h"
#include "GameFramework/Actor.h"
#include "TirggetVolEventListener.generated.h"
//전방선언 헤더에 추가안하는 대신
class AMyTriggetrVolume;
UCLASS()
class WILLIAM_API ATirggetVolEventListener : public AActor
{
GENERATED_BODY()
public:
UPROPERTY()
UPointLightComponent* PointLight;
UPROPERTY(EditAnywhere)
AMyTriggetrVolume* TriggerEventSource;
UFUNCTION()
void OnTriggerEvent();
public:
ATirggetVolEventListener();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
};
ATirggetVolEventListener.Cpp
#include "TirggetVolEventListener.h"
#include "MyTriggetrVolume.h"
ATirggetVolEventListener::ATirggetVolEventListener()
{
PrimaryActorTick.bCanEverTick = true;
PointLight = CreateDefaultSubobject<UPointLightComponent>("PointLight");
RootComponent = PointLight;
}
void ATirggetVolEventListener::BeginPlay()
{
Super::BeginPlay();
if(TriggerEventSource !=nullptr)
{
TriggerEventSource->OnPlayerEntered.AddUObject(this, &ATirggetVolEventListener::OnTriggerEvent);
}
}
void ATirggetVolEventListener::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ATirggetVolEventListener::OnTriggerEvent()
{
PointLight->SetLightColor(FLinearColor(0, 1, 0, 1));
}
다른 모든 타입의 델리게이트와 마찬가지로 이벤트에는 이벤트만의 매크로 함수가 필요하다.

첫번째 파라미터는 이벤트가 구현될 클래스다.
BroadCast()를 호출할 수 있는 유일한 클래스이므로 올바른 클래스인지 확인한다.
두번째 파라미터는 새 이벤트 함수 시그너치의 타입이름이다.
실행화면은 PASS
'UnraealEngine' 카테고리의 다른 글
| UE5 C++ 멀티플레이어: RPC & 리플리케이션 심층 가이드 (0) | 2025.03.13 |
|---|---|
| Unreal4 이벤트와 델리게이트 처리하기 5)TimeofDay 핸들러 생성 (0) | 2021.08.25 |
| Unreal4 이벤트와 델리게이트 처리하기 4)멀티캐스트 델리게이트 생성 (0) | 2021.08.24 |
| Unreal4 이벤트와 델리게이트 처리하기 3)입력 파라미터를 사용하는 델리게이트 생성 (0) | 2021.08.24 |
| Unreal4 이벤트와 델리게이트 처리하기 2)델리게이트 등록 및 해제 (0) | 2021.08.24 |