OnComponentEndOverlap is never fired [UE 4.10]

Hi, I was doing a FP item grab mechanism in C++. When the player overlaps the item it should set a boolean variable (bIsWithinRange) to true, and when it’s not overlaping it should set the variable to false. I use this variable as a condition check for the player to be able to pick the item up.

Everything is working fine except OnComponentEndOverlap, which seems to be never firing. Any ideas? Code below…

AItem::AItem()
{
 	// 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;

	TBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));
	TBox->bGenerateOverlapEvents = true;
	TBox->OnComponentBeginOverlap.AddDynamic(this, &AItem::TriggerEnter);
	TBox->OnComponentEndOverlap.AddDynamic(this, &AItem::TriggerExit);

	RootComponent = TBox;

	SM_TBox = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Box Mesh"));
	SM_TBox->AttachTo(RootComponent);

}

void AItem::TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult) {
	bItemIsWithinRange = true;
	GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Green, FString::Printf(TEXT("Press E to pickup %s"), *ItemName));
	GetPlayer(OtherActor);
}

void AItem::TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) {
	bItemIsWithinRange = false;
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("EndOverlap"))); //To check if this function is called. It's never called.
}

Did you maybe forget to mark your TriggerExit function as UFUNCTION?

Thanks PrinfD! Actually I didn’t forget, but your answer made me think about trying something I haven’t. The declarations were like this:

UFUNCTION()
		void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
		void TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

Looks like this doesn’t work, so I tried this:

UFUNCTION()
		void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
UFUNCTION()
		void TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

Thank you very much!

Always happy to help.

The behavior is actually expected, as the UFUNCTION() makro only marks the next function declaration as UFUNCTION, that’s why you have to use it before each of those functions.

Dayumm - Was scratching my head for an hour trying to work this out, and it was just because I was silly enough to forget the UFUNCTION() macro.
Finally google and answerhub came through haha. Good tip PrinfD lol.