OnComponentHit does not work

As in title, my code is: In construcor

.h ////////////////////////////////////////////////////

ASafeLineClickEvent();

UFUNCTION()
virtual void OnHit(UPrimitiveComponent * HitComponent, AActor * OtherActor, UPrimitiveComponent * OtherComponent, FVector NormalImpulse, const FHitResult & Hit);

.cpp ///////////////////////////////////////////////

ASafeLineClickEvent::ASafeLineClickEvent()

{

PrimaryActorTick.bCanEverTick = true;
CBoxCom = CreateDefaultSubobject(TEXT(“CboxCom”));
CBoxCom->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
CBoxCom->bGenerateOverlapEvents = true;
FScriptDelegate Delegate;
Delegate.BindUFunction(this, “OnHit”);
CBoxCom->OnComponentHit.AddUnique(Delegate);
CBoxCom->SetRelativeLocation(FVector::ZeroVector);
CBoxCom->SetNotifyRigidBodyCollision(true);

RootComponent = CBoxCom;

}

void ASafeLineClickEvent::OnHit(UPrimitiveComponent * HitComponent, AActor * OtherActor, UPrimitiveComponent * OtherComponent, FVector NormalImpulse, const FHitResult & Hit)

{

GEngine->AddOnScreenDebugMessage(1, -5.f, FColor::Yellow, TEXT("Hit!"));
UE_LOG(LogTemp, Warning, TEXT("I'm hit, I'm hit"));
if (OtherActor && (OtherActor != this))
{
	GEngine->AddOnScreenDebugMessage(1, -5.f, FColor::Yellow, TEXT("Hit!"));
}

}

And object collision preset settings

And other collision settings to interact with

Try this instead:

.h File:

UFUNCTION()
void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

.cpp File:

CBoxCom->OnComponentHit.AddDynamic(this, &ASafeLineClickEvent::OnHit);

The issue is likely occuring because your OnHit() function parameters are wrong, and so the function signature doesn’t match.

Thanks, but it does not work as you say.

If there are several overlapping collisions in the place where Hit happens, is it not Hit?