OnComponentBeginOverlap AddDynamic not working

So, the same code is working on some assets, collisions are working, cos in blueprint the overlap works, te code on the cpp is:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Box Collision”)
BoxComponentToGrabHammer = CreateDefaultSubobject(TEXT(“Collision To Grab”));
BoxComponentToGrabHammer->SetupAttachment(StaticMesh);
BoxComponentToGrabHammer->SetGenerateOverlapEvents(true);
BoxComponentToGrabHammer->OnComponentBeginOverlap.AddDynamic(this, &AHammerC::GrabhammerBeginPlay);

void AHammerC::GrabhammerBeginPlay(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT(“GrabHammerOverlap”));
}

In the past, just deleting the Binaries Intermediate and DerivedDataCache and rebuild worked, but this time it is not

It is not the full code on “GrabhammerBeginPlay()” so is easier to read

Hey,

When you say its not working what exactly do you mean?

There are a few options that could be the reason for this not working here:

  • Is GrabhammerBeginPlay a UFUNCTION()
  • Are the collision settings setup correctly so that this actually get triggered. Looking at the Profile as I see you already set GenerateOverlapEvents to true.
1 Like

If you aren’t familiar with the Collision system this is a great video explaining this - https://www.youtube.com/watch?v=xIQI6nXFygA

1 Like

Yeah maybe is the “UFUNCTION()” I started some week ago with C++, cos I have been coding in blueprint for 11 years. Thank you so much it was the UFUNCTION the solution, I remember that in the other begin play I put the UFUNCTION().

No worries glad to help :smiley:

1 Like