Colliders dont send OnCollisionEnter

Hello!
Im having one of my first issues with Unity :slight_smile:

I have setup the funny unity spaceship as in the picture:

The object hierarchy consist of a gameObject “SpaceShip” with a rigidBody and a control script in it, as Parent. The colliders, however, are distributed in three other gameObjects: “Capsule” wich has the sphere collider in the picture, and the “leftLeg” and “rightLeg” (box colliders in the picture).

Now I added an script to each leg, hoping the colliders to send the OnCollisionEnter event, but they simply dont. I tested adding a rigid body to each leg, and then the event will be called… however, if I understood the docs right, the colliders should attach themselves to the first rigidBody found in the parent chain, so theoretically, it should work without the awkward need for a rigidBody on each leg.

Could someone help me out understanding what Im missing?
Thanks!

you’re probably looking for a compound collider, which means several collision objects and one rigid body. To set that up:

parent game object - has rigid body
-----child game object with collider
-----child game object with collider
-----child game object with collider

And so on. Then when you want to look for collisions you need to check collisions in a different way. You need to loop through CONTACT POINTS instead: Unity - Scripting API: Collider.OnCollisionEnter(Collision)

That shows clearly, looping through the contact points. The reason for this is it is a hierarchy and you’ll have to loop through them: Unity - Scripting API: ContactPoint

Btw, you pretty much do need a rigid body of some sort for decent OnCollisionStay though, as for some reason it’s a little buggy there without rigid bodies.

Collision messages are never sent to children when using compound colliders, only the parent. The point of compound colliders is that they act like a single collider.

–Eric

Ah! so I shall put the script in the Parent object, and look through the contact points to see where the collision happened. I’ll try that, thanks very much guys!