Box collision - OnOverlapBegin and OnOverlapEnd not invoking?

Hello,
I am creating WeaponPickup Actor.

In header file I have this:

    void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
	void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex);

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Apperance", meta = (AllowPrivateAccess = "true"))
	UBoxComponent* BoxComponent;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Apperance", meta = (AllowPrivateAccess = "true"))
    class UStaticMeshComponent* BaseMesh;

And in cpp in the constructor this:

   //Base mesh
	BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
	BaseMesh->SetupAttachment(RootComponent);

	//Collision
	BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
	BoxComponent->SetupAttachment(BaseMesh);
	BoxComponent->SetWorldScale3D(FVector(1.0f, 1.0f, 1.0f));
	BoxComponent->SetWorldLocation(FVector(0.f, 0.f, 0.f));

	BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AWeaponPickup::OnOverlapBegin);
    BoxComponent->OnComponentEndOverlap.AddDynamic(this, &AWeaponPickup::OnOverlapEnd);

And at the end of the file two methods:

void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Some debug message!"));  
}

void AWeaponPickup::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex)
{
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Some debug message!"));  
}

My problem is that this messages are never showed up I can walked into pickup, leave him and nothing happend. I checked BoxComponent and Collision is enabled (OverlapAll) and Generate Overlap Events is too enabled…

Try making both of them UFUNCTION() in the header file. Sometimes the engine just doesn’t seem to know things exist unless you tag them with the macros.

I tried, but It still doesnt work.

Hmm…Well, everything else looks fine. You made the component. You bound the functions. I didn’t check, but I assume it would give you an error if you got the arguments wrong on anything.

I’m stumped too. I guess just turn everything off and on again. lol

I solved It…

BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AWeaponPickup::OnOverlapBegin);
BoxComponent->OnComponentEndOverlap.AddDynamic(this, &AWeaponPickup::OnOverlapEnd);

If u have this in constructor it doesnt work, but when u place it into BeginPlay it works

As with a lot of things, Ureal doesn’t like it when you handle stuff in your constructor.

Calling AddDynamic in the constructor may cause the invocation list to be cleared between the constructor and begin play. That’s why it’s always better to call this at BeginPlay().