# Detect Child Trigger inside Parent Script

I want to detect when a Child's collider is being triggered to apply the damage to the thing being hit. But currently I'm confused about how it works.

Does the Parent's OnTriggerEnter detect the trigger events of the Child Object ? And how do I know the trigger come from the Child and not the Parent, and know which Child's collider got triggered?

The Parent's collider is not a trigger, but the Child's collider is.

• Who is this evil parent that mashes his child around like that? May 31 at 9:20
• Actually make me lols May 31 at 9:27
• May 31 at 10:56

## 1 Answer

Triggers don't create OnTriggerXXX messages, only rigidbodies do. If child doesn't have a rigidbody, basically its collider is considered a child collider of the parent node (compound collider). Now we come back to the question:

Does the Parent's OntriggerEnter detect the trigger event of the Child Object ?

If child object doesn't have a rigidbody, yes.

And how do I know the trigger come from the Child and not the Parent and know which Child's collider got triggered ?

They need their own rigidbody and script with OntriggerEnter, which is not recommended.

In fact, you don't need to get the physical events from the attack box, simply set it to another layer, such as "attack", and all attack events are handled by the attacked party (character's body, with rigidbody and script, layer "be_attacked").

• Oh so I can check the GameObject layer that being hit in the OnTrigger and see if it's the layer I want to get hit by the Child's Collider ? May 31 at 9:14
• You can set the Collision Matrix in Edit > Project Settings. So that collision will only happen between the objects you want. May 31 at 9:24
• Thanks @Mangata that's really helpful I got it now May 31 at 9:26