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
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
#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?