OnHit not working correctly C++

I have tried to create an OnHit function and I have attached it to my base sphere component:

BaseCollisionComponent->OnComponentHit.AddDynamic(this, &ABaseProjectile::OnHit);

Whenever my projectile actor touched anything this never fired. The contents of the OnHit is to just destroy the actor.
After looking through all the different collision presets I used the blueprint OnHit nad made my OnHit blueprint callable:

This made it work. So now I am confused as to why just using C++, the OnHit isn’t called?

Hi Crabbo,

Event Hit and Component Hit it is different functions. I think collision properties can be reason of different behavior of these functions. Try to this function:

OnActorHit.AddDynamic(this, &ABaseProjectile::OnHitActor);

Hope it helps!

I get where this is coming from but I have ran into this problem:

[BaseProjectile.h]
USphereComponent* BaseCollisionComponent;
[]

[BaseProjectile.cpp]

BaseCollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));
	BaseCollisionComponent->InitSphereRadius(5.0f);
	BaseCollisionComponent->BodyInstance.SetCollisionProfileName("Projectile");
	BaseCollisionComponent->OnActorHit.AddDynamic(this, &ABaseProjectile::OnHit);

	//Set sphere to be root component
	RootComponent = BaseCollisionComponent;

My problem is that the sphere component does not have an OnActorHit() function. Is there any other functions I should be looking at to use to get the collisions correct?

OnActorHit it is actor delegate, not component.

Also, try to use it

BaseCollisionComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly);

BaseCollisionComponent ->SetCollisionResponseToAllChannels(ECR_Block);

Thank you for the help. To fix it I used:

this->OnActorHit.AddDynamic(this, &ABaseProjectile::OnHit);

But I had to change my OnHit attributes from:

ABaseProjectile::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)

To:

ABaseProjectile::OnHit(AActor* SelfActor, AActor* OtherActor, FVector NormalImpulse, const FHitResult& Hit)

Thanks again for the help.