Question
Given the following hierarchy of objects/components:
Parent Object : rigidbody |_ Child Object 1 : mesh filter, mesh renderer, mesh collider |_ Child Object 2 : mesh filter, mesh renderer, mesh collider
I want to detect when one of the child objects is hit. I’ve created a basic collision detection script using the OnCollisionEnter callback however the collision event callback is not fired.
public void OnCollisionEnter(Collision collision)
{
Debug.Log("Collision detected on " + gameObject.name);
}
** Investigation **
If I take the child object and add a rigidbody without changing anything else, this works fine:
Parent Object : rigidbody |_ Child Object 1 : mesh filter, mesh renderer, mesh collider, rigidbody |_ Child Object 2 : mesh filter, mesh renderer, mesh collider, rigidbody
However this gives the incorrect behaviour (it’s no longer a composite rigidbody) and I want to avoid having to join all the child objects together with constraints.
In the desired hierarchy, detecting collision on the projectile works fine. I’m guessing the problem is something to do with the mesh collider and rigidbody being on different objects.
The documentation states:
A Collider does not necessarily need a rigidbody attached, but a rigidbody must be attached in order for the object to move as a result of collisions.
And the object does indeed move after it has been hit correctly, I just don’t get the collision event.
Any help greatly appreciated!