OnComponentBeginOverlap C++

.h

UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
USphereComponent * SphereComp;

.cpp

	SphereComp = CreateDefaultSubobject <USphereComponent>(TEXT("SphereComp"));
	SphereComp->SetCollisionProfileName(TEXT("Collision"));
	SphereComp->SetupAttachment(RootComponent);
	SphereComp->OnComponentBeginOverlap.AddDynamic(this, &AArrow::OnOverlapBegin);
}

void AArrow::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Overlap"));
	}
}

Idk why but its not Overlapping.

Nvm, I found what was wrong…

For those who are having the same issue:
If u create the BP based on your c++ code, and then modify later the c++ code, u should re-create the BP file. Seems like that when u create the BP before, on a way it bug and dont compile propely.

1 Like