OnComponentHit triggering multiple times

I am trying to decrease the number of lives a player has when a ball hits an actor marked with the “deadzone” tag but sometimes, when the ball hits the deadzone, 2,3 or 4 lives are removed and I do not know why. Here is my OnHit code:

void ABall::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit)
{
	// Other Actor is the actor that triggered the event. Check that is not ourself.  
	if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComponent != nullptr))
	{
		if (OtherActor->ActorHasTag("DeadZone") /*&& !bHasCollided*/)
		{
			//UE_LOG(LogTemp, Warning, TEXT("Dead"));
			BallMeshComponent->SetRelativeLocation(StartingLocation);
			BallMeshComponent->SetSimulatePhysics(false);		
			bIsLaunched = false;

			CurrentNumberOfLives--;
			//bHasCollided = true; //I can prevent multiple hits with a boolean but would rather understand why it's happening
		}
	}
}

When I use a breakpoint to debug, I can see that the function is called multiple times, but I really don’t know why. Sometimes it works fine, but most of the time, it’s triggered on multiple occasions. Any help appreciated.

I’ve also tried this with NotifyHit(class UPrimitiveComponent* MyComp, AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit) but I am experiencing the same behaviour so I do not believe the issue lies with OnComponentHit

Can you please share a git repo for your project? … this looks strange issue…

Have the same issue. Looks like it depends on a count of supsteps (Physics Substepping). Tested on 4.22.0

Try SetNotifyRigidBodyCollision(false) inside OnHit to make it not call it again after the 1st time

And it will never call again =)

You can use a timer to set it back up, or whatever logic you’re using in it.