OnComponentBeginOverlap not triggering

Hello!

I’ve always used the actor begin overlap (and it always works fine):

void NotifyActorBeginOverlap(class AActor* OtherActor) override;

However, on using ‘OnComponentBeginOverlap’ it won’t fire.

This should be basic but I can’t see the issue…

[I did this in a fresh project as a test example to show code, still not working…]

ATestBridge [.h]

	// Root
	UPROPERTY(VisibleDefaultsOnly, Category = Mesh, meta = (AllowPrivateAccess = "true"))
	class USceneComponent* RootComp;

	// Player Collision Overlap
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Overlap)
	class UBoxComponent* PlayerOverlap;

    // Trigger overlap
	void TriggerEnterMain(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

ATestBridge [.cpp]

ATestBridge::ATestBridge()
{
	PrimaryActorTick.bCanEverTick = true;

	// Root
	RootComp = CreateDefaultSubobject<USceneComponent>(TEXT("RootComp"));
	SetRootComponent(RootComp);

	// Player Collision Overlap
	PlayerOverlap = CreateDefaultSubobject<UBoxComponent>(TEXT("PlayerOverlap"));
	PlayerOverlap->SetupAttachment(RootComponent);    
	PlayerOverlap->SetGenerateOverlapEvents(true);
	PlayerOverlap->OnComponentBeginOverlap.AddDynamic(this, &ATestBridge::TriggerEnterMain);
}

void ATestBridge::TriggerEnterMain(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Yellow, FString::Printf(TEXT("TRIGGER ENTER")));
}

In the Blueprint I set the collision to be ‘OverlapAll’ and also ‘Generate Overlap Events’ is true (set in code).

I place the BP in the world, scale it up and no matter what goes in the trigger (Player, phys object etc.) it won’t fire the function.

NOTE: If I use the NotifyActorBeginOverlap - it works fine.

Anyone any ideas what I’ve done wrong?

Sigh! I missed the UFUNCTION() macro on the function defines.

If anyone gets stuck - it should be like this in the header:

UFUNCTION()    
void TriggerEnterMain(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
1 Like