# OnComponentBeginOverlap doesnt work

**URL:** <https://forums.unrealengine.com/t/oncomponentbeginoverlap-doesnt-work/400814>\
**Category:** C++\
**Tags:** oncomponentbeginover, unreal-engine, CPP, question\
**Created:** [July 28, 2017, 6:29pm UTC](https://forums.unrealengine.com/t/oncomponentbeginoverlap-doesnt-work/400814 "2017-07-28T18:29:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_f0965973](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f0965973](https://forums.unrealengine.com/u/anonymous_user_f0965973)\
**Post date:** [July 28, 2017, 6:29pm UTC](https://forums.unrealengine.com/t/oncomponentbeginoverlap-doesnt-work/400814/1 "2017-07-28T18:29:29Z")

</div>

When I play the setup, PickupBox doesn’t destroy. My character bumps into him and can not destroy the PickupBox as expected form the code. I enabled/checked all Genrate Overlap Events’ checkboxes for the pickupbox and my character… but I still can not destroy the object. When I enter/touch pickupbox, it doesn’t do anything… just blocks my character when touched/approached. Any help will be appreciated.

Here is the code:

/**------------------------------------------------------------------------------------------------------------------------------------  
Pickup.h  
------------------------------------------------------------------------------------------------------------------------------------**/

#include “CoreMinimal.h”  
#include “GameFramework/Actor.h”  
#include “Components/BoxComponent.h”  
#include “Pickup.generated.h”

UCLASS()  
class SAFARICOOKBOOKDEMO\_API APickup : public AActor  
{  
GENERATED\_BODY()

public:   
// Sets default values for this actor’s properties  
APickup();

```
UPROPERTY(EditAnywhere)
UBoxComponent* PickupBox;
UPROPERTY(EditAnywhere)
UStaticMeshComponent* PickupMesh;
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, 
	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

```

protected:  
// Called when the game starts or when spawned  
virtual void BeginPlay() override;

public:   
// Called every frame  
virtual void Tick(float DeltaTime) override;

};

/**------------------------------------------------------------------------------------------------------------------------------------  
Pickup.cpp  
------------------------------------------------------------------------------------------------------------------------------------**/  
#include “…/Public/Pickup.h”

// Sets default values  
APickup::APickup()  
{  
// 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;

```
PickupBox = CreateDefaultSubobject<UBoxComponent>("PickupBox");
PickupBox->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnOverlapBegin);
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>("PickupMesh");

```

}

void APickup::OnOverlapBegin(UPrimitiveComponent\* OverlappedComponent, AActor\* OtherActor,  
UPrimitiveComponent\* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)  
{  
Destroy();  
}

// Called when the game starts or when spawned  
void APickup::BeginPlay()  
{  
Super::BeginPlay();

}

// Called every frame  
void APickup::Tick(float DeltaTime)  
{  
Super::Tick(DeltaTime);

}
