OnHit doesn't do anything

Hi,
I’m following along in the ToonTanks section and I’ve got the ProjectileBase all set up like the instructor, as far as I can tell:

ProjectileBase.h:

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

ProjectileBase.cpp:

void AProjectileBase::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpuse, const FHitResult& Hit)
{
	AActor* MyOwner = GetOwner();
	if (!MyOwner)
	{
		return;
	}
	
	if(OtherActor && OtherActor != this && OtherActor != MyOwner)
	{
		UGameplayStatics::ApplyDamage(OtherActor, Damage, MyOwner->GetInstigatorController(), this, DamageType);
	}

	Destroy();
}

But for some reason I can’t get the OnHit() to fire. I even tried putting a UE_LOG right at the beginning of OnHit() to see if it was being interrupted somewhere in the middle, but the log never even fired.

Am I missing something here?

Where did you use AddDynamic?

Thanks Dan, your comment pointed me in the right direction.

I had it in the constructor, and I hadn’t noticed the instructor’s warning at the beginning. After deleting and recreating the blueprint (since I wanted to keep AddDynamic in the constructor), it’s working now.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms