# OnComponentHit triggering multiple times

**URL:** <https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130>\
**Category:** World Creation\
**Tags:** multiple, unreal-engine, Physics, hit-event, Collision, question\
**Created:** [March 27, 2019, 9:48pm UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130 "2019-03-27T21:48:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JayFitz91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JayFitz91](https://forums.unrealengine.com/u/JayFitz91)\
**Post date:** [March 27, 2019, 9:48pm UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130/1 "2019-03-27T21:48:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JayFitz91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JayFitz91](https://forums.unrealengine.com/u/JayFitz91)\
**Post date:** [March 28, 2019, 9:23pm UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130/2 "2019-03-28T21:23:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![emperor\_katax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emperor_katax/32/1070178_2.png) [@emperor\_katax](https://forums.unrealengine.com/u/emperor_katax)\
**Post date:** [March 29, 2019, 4:48am UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130/3 "2019-03-29T04:48:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Creo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Creo](https://forums.unrealengine.com/u/Creo)\
**Post date:** [May 26, 2019, 12:39pm UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130/4 "2019-05-26T12:39:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lobotomiac](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lobotomiac](https://forums.unrealengine.com/u/Lobotomiac)\
**Post date:** [May 30, 2019, 1:34pm UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130/5 "2019-05-30T13:34:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Creo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Creo](https://forums.unrealengine.com/u/Creo)\
**Post date:** [May 30, 2019, 1:38pm UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130/6 "2019-05-30T13:38:30Z")

</div>

And it will never call again =)

---

<div class="post-metadata">

**Author:** ![Lobotomiac](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lobotomiac](https://forums.unrealengine.com/u/Lobotomiac)\
**Post date:** [May 30, 2019, 1:56pm UTC](https://forums.unrealengine.com/t/oncomponenthit-triggering-multiple-times/446130/7 "2019-05-30T13:56:58Z")

</div>

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