# Different behaviour between OnComponentHit.AddDynamic and EventHit

**URL:** <https://forums.unrealengine.com/t/different-behaviour-between-oncomponenthit-adddynamic-and-eventhit/827163>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, CPP, Blueprint, question\
**Created:** [March 27, 2023, 10:40am UTC](https://forums.unrealengine.com/t/different-behaviour-between-oncomponenthit-adddynamic-and-eventhit/827163 "2023-03-27T10:40:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emrayce](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Emrayce](https://forums.unrealengine.com/u/Emrayce)\
**Post date:** [March 27, 2023, 10:40am UTC](https://forums.unrealengine.com/t/different-behaviour-between-oncomponenthit-adddynamic-and-eventhit/827163/1 "2023-03-27T10:40:47Z")

</div>

Hello!

I’m making a space invader and I started by creating the shooting mechanism.  
I have Aliens that should be destroyed whent hit by something and Projectile that should be destroyed when they hit something.  
I’m making it in C++ so I use for both in BeginPlay **OnComponentHit.AddDynamic()** with an OnHit function that destroy the object and print a debug.  
In game, projectiles do behave correctly, but aliens don’t. They destroy themself after being hit a random amount of hits instead of one just like the projectile. It also seems that the projectile destroy themself just before hitting the alien. If I use the player to hit an Alien then same thing: it destroy itself after a random number of hits.  
 ![With-script](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/8/3/183c7f371199c80bb2d5bf0d4d7698f46a2e9df8.gif)

However if I’m using on the Alien blueprint **EventHit-\>DestroyActor()** then it works perfectly. Projectile seems to touch the Alien and the Alien destroy itself when touched.  
 ![With-blueprint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/a/4/5a4bb25ed47e34dc3b4d74776e43dc2fbc5b9a61.gif)

I don’t understand why this is happening and I would like to use my C++ code for the Alien class too.

If you need more informations to help me with that I will gladly give them to you.

---

<div class="post-metadata">

**Author:** ![Emrayce](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Emrayce](https://forums.unrealengine.com/u/Emrayce)\
**Post date:** [April 1, 2023, 4:39pm UTC](https://forums.unrealengine.com/t/different-behaviour-between-oncomponenthit-adddynamic-and-eventhit/827163/2 "2023-04-01T16:39:14Z")

</div>

I think I resolved my problem.  
I didn’t set up the native collider of the static mesh to NoCollision. Projectiles were hitting this native collider and not the component Colldier I added.  
**OnComponentHit** bind an action on the Collider component not on the static mesh one.  
In the blueprint graph event EventHit bind an action on the native collider not the component one.  
This is why alien where destroyed correctly with EventHit

**OnComponentHit** can also be used in a blueprint but you first need to get the collider.
