Is it possible to fire an OnCollisionEnter() on a child GameObject?

Hi there!

It seems that I’ve run into yet another small problem. I’d like to use a script attached to my Prefab to perform (an event similar to) the OnCollisionEnter()/ OnTriggerEnter() function on it’s children. I do have a back-up plan which involves 3 seperate scripts (one for each child) and communicating between them and the main script, but I’d much rather do it from a single central one.
I’d prefer to use the childrens’ Box Colliders, so I’d rather not use the OverlapSphere approach.

As always, all help will be much appreciated.

-Patrick

Aah, I forgot to mention this, but it’s crucial to know which Child caused the collision. Anyone? =) I’ve come to terms with having to deal with 3 scripts, but I think I may be overlooking something.

you can use the collider to find out about the child.
alternatively keep in mind that the collision event is fired upwards in the hierarchy until it hits the first parent which contains a rigidbody

Thanks for your quick response Dreamora. =) Could you tell me how I could use the Collider to find out which Child was hit? (I’m probably missing the obvious here… =P)

The Collision object that gets passed to OnCollisionEnter contains a field for the collider that was hit (ie, it will return the specific child collider, not the parent rigidbody object). The Collider object then has fields for obtaining the Transform, GameObject, etc.

Hey Andeeee,

Thanks for your response. I actually needed to go the other way (finding out which of the three Children of my ‘Empty’ Parent hit the external collider). :wink: However, due to major time constraints today I opted for three quick and dirty individual scripts. Thanks again for your help though! =)