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.
}