OnComponentBeginOverlap doesnt work

anonymous_user_f0965973
Fri, 28 Jul 2017 18:29:29 +0000
C++

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);

}

1 post - 1 participant