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