How to do it...

  1. Add the following event declaration macro to the header of your MyTriggerVolume class:
DECLARE_EVENT(AMyTriggerVolume, FPlayerEntered) 
  1. Add an instance of the declared event signature to the class:
FPlayerEntered OnPlayerEntered; 
  1. In AMyTriggerVolume::NotifyActorBeginOverlap, add the following code:
OnPlayerEntered.Broadcast();

  1. Create a new Actor class called TriggerVolEventListener:

  1. Add the following class members to its declaration:
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/PointLightComponent.h"
#include "MyTriggerVolume.h"
#include "TriggerVolEventListener.generated.h"

UCLASS()
class CHAPTER_05_API ATriggerVolEventListener : public AActor
{
GENERATED_BODY()

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

UPROPERTY()
UPointLightComponent* PointLight;

UPROPERTY(EditAnywhere)
AMyTriggerVolume* TriggerEventSource;

UFUNCTION()
void OnTriggerEvent();

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

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

};
  1. Initialize PointLight in the class constructor:
// Sets default values
ATriggerVolEventListener::ATriggerVolEventListener()
{
// 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;

PointLight = CreateDefaultSubobject<UPointLightComponent>
("PointLight");

RootComponent = PointLight;
}
  1. Inside BeginPlay, add the following code:
// Called when the game starts or when spawned
void ATriggerVolEventListener::BeginPlay()
{
Super::BeginPlay();

if (TriggerEventSource != nullptr)
{
TriggerEventSource->OnPlayerEntered.AddUObject(this,
&ATriggerVolEventListener::OnTriggerEvent);

}

}
  1. Lastly, implement OnTriggerEvent():
void ATriggerVolEventListener::OnTriggerEvent() 
{ 
  PointLight->SetLightColor(FLinearColor(0, 1, 0, 1)); 
}

  1. Compile your project and launch the editor. Create a level with the game mode set to our Chapter_05GameModeBase, and then drag an instance of ATriggerVolEventListener and AMyTriggerVolume out into the level.
  2. Select TriggerVolEventListener, and you'll see TriggerVolEventListener listed as a category in the Details panel, with the property asĀ Trigger Event Source:

The Trigger Vol Event Listener category
  1. Use the drop-down menu to select your instance of AMyTriggerVolume so that the Listener knows which event to bind to:

  1. Play your game and enter the trigger volume's zone of effect. Verify that the color of your EventListener changes to green: