# Cannot bind OnComponentHit

**URL:** <https://forums.unrealengine.com/t/cannot-bind-oncomponenthit/358625>\
**Category:** Community & Industry Discussion\
**Tags:** oncomponenthit, capsulecomponent, binding, unreal-engine, question\
**Created:** [May 26, 2016, 9:38am UTC](https://forums.unrealengine.com/t/cannot-bind-oncomponenthit/358625 "2016-05-26T09:38:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cridia](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cridia/32/772487_2.png) [@cridia](https://forums.unrealengine.com/u/cridia)\
**Post date:** [May 26, 2016, 9:38am UTC](https://forums.unrealengine.com/t/cannot-bind-oncomponenthit/358625/1 "2016-05-26T09:38:04Z")

</div>

I am having a bit of a problem binding OnComponentHit to one of my capsule components. The problem is that the implementation worked before and when I cleaned up the class (moving some variables around to make it more readable), it just stopped working. Not sure whether that is actually the cause, but thought I should mention. Anyways, as for the code:

**.h**

```
UFUNCTION()
	void OnFrontalCapsuleHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

```

**.cpp**

```
FrontalHitCheckCapsule->SetNotifyRigidBodyCollision(true);
FrontalHitCheckCapsule->OnComponentHit.AddDynamic(this, &MyCharacter::OnFrontalCapsuleHit);

void MyCharacter::OnFrontalCapsuleHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	UE_LOG(AnyLog, Log, TEXT("Got a hit"));
}

```

I have doublechecked the capsule components in the blueprint, and all of the relevant ones had the NotifyRigidBodyCollision set to true. I also tried binding it to the default CapsuleComponent instead of the one I added, but no luck there either. Would love to get this solved, as not being able to assign an OnHit kinda messes with the gameplay I was planning on implementing.

---

<div class="post-metadata">

**Author:** ![cridia](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cridia/32/772487_2.png) [@cridia](https://forums.unrealengine.com/u/cridia)\
**Post date:** [May 27, 2016, 12:32am UTC](https://forums.unrealengine.com/t/cannot-bind-oncomponenthit/358625/2 "2016-05-27T00:32:05Z")

</div>

I have done some more experiments, and the problem is becoming weirder and weirder.

I have done 3 checks.  
-First I checked whether the object was bound using IsBound(), which returned true.  
-Secondly I checked more specifically using Contains(this, “OnFrontalCapsuleHit”), which also returned true.  
-Lastly I checked which objects were bound by using GetAllObjects(), and confirmed that it was bound only to my character.

Despite all this, the function is just not being called on an actual hit.

---

<div class="post-metadata">

**Author:** ![TempDN3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TempDN3](https://forums.unrealengine.com/u/TempDN3)\
**Post date:** [July 11, 2016, 10:53am UTC](https://forums.unrealengine.com/t/cannot-bind-oncomponenthit/358625/3 "2016-07-11T10:53:00Z")

</div>

OK, I hope this helps you.

This is the code I’m using in my project:

```
PickupCollisionSphere->OnComponentHit.AddDynamic(this, &APickup::HitTheGround);

void APickup::HitTheGround(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)

```

I was staring at the blueprint thingie for OnComponentHit and noticed that there’s a ‘ **Hit Component** ’ in front of the ‘ **Other Actor** ’ and your parameters didn’t include it.  
Could this be the cause of your problems?

I’m using 4.12 btw.

---

<div class="post-metadata">

**Author:** ![cridia](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cridia/32/772487_2.png) [@cridia](https://forums.unrealengine.com/u/cridia)\
**Post date:** [September 13, 2016, 6:00am UTC](https://forums.unrealengine.com/t/cannot-bind-oncomponenthit/358625/4 "2016-09-13T06:00:45Z")

</div>

Sorry, that wasn’t really my problem. With 4.12 they changed the signature a bit, adding an additional argument. If my problem was that of a lacking argument in my OnHit function, it would never have compiled to begin with. The problem here was that even though OnHit was bound and everything, it never actually fired.

The problem solved itself when I switched engines, so I still don’t know exactly what was wrong there.
