# UBoxComponenet C++ OnOverlapEvent not firing. I don't understand what I am doing wrong

**URL:** <https://forums.unrealengine.com/t/uboxcomponenet-c-onoverlapevent-not-firing-i-dont-understand-what-i-am-doing-wrong/1386626>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, CPP, question, box-overlap, overlap-event\
**Created:** [November 13, 2023, 6:07am UTC](https://forums.unrealengine.com/t/uboxcomponenet-c-onoverlapevent-not-firing-i-dont-understand-what-i-am-doing-wrong/1386626 "2023-11-13T06:07:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHOBBIT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SHOBBIT](https://forums.unrealengine.com/u/SHOBBIT)\
**Post date:** [November 13, 2023, 6:07am UTC](https://forums.unrealengine.com/t/uboxcomponenet-c-onoverlapevent-not-firing-i-dont-understand-what-i-am-doing-wrong/1386626/1 "2023-11-13T06:07:11Z")

</div>

Hello,

I’ve been struggling to get the overlap event to work from my C++ code. Can someone help me understand what is the issue? My code compiles without an error but fails to work when the overlap happens in the game.

Header File Relevant code

```auto
class UBoxComponent;

	// A box volume trigger which on overlap will destroy self
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	UBoxComponent* EndTrigger;

	// Function to perform operations when character overlaps the EndTrigger
	void OnEndTriggerBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

```

In the CPP File

```auto
#include "Components/BoxComponent.h"

	// Initialize the box component - EndTrigger
	EndTrigger = CreateDefaultSubobject<UBoxComponent>(TEXT("EndTrigger"));
	EndTrigger->SetRelativeLocation(FVector(2000.0f, 0.0f, 0.0f));
	EndTrigger->SetBoxExtent(FVector(0.0f, 2000.0f, 2000.0f));
	EndTrigger->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
	EndTrigger->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
	EndTrigger->SetGenerateOverlapEvents(true);
	EndTrigger->SetupAttachment(SceneRoot);

void AMyActor::BeginPlay()
{
	Super::BeginPlay();
	EndTrigger->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OnEndTriggerBeginOverlap);
	
}

void AMyActor::OnEndTriggerBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	PrintStringToLog(TEXT("EndTriggerOverlap called"));
	Destroy();

}

```

The above however log/function however never gets fired. Can someone tell me what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![SHOBBIT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SHOBBIT](https://forums.unrealengine.com/u/SHOBBIT)\
**Post date:** [November 13, 2023, 7:23am UTC](https://forums.unrealengine.com/t/uboxcomponenet-c-onoverlapevent-not-firing-i-dont-understand-what-i-am-doing-wrong/1386626/2 "2023-11-13T07:23:54Z")

</div>

Okay, I figured it out by looking at a sample project reference. I forgot to add the UFUNCTION() Macro

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [December 13, 2023, 7:24am UTC](https://forums.unrealengine.com/t/uboxcomponenet-c-onoverlapevent-not-firing-i-dont-understand-what-i-am-doing-wrong/1386626/3 "2023-12-13T07:24:24Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
