2
\$\begingroup\$

I created a sphere object, added a rigidbody component (no kinematics) and attached a script to it like this:

function Update () {
}

function OnCollisionEnter(collision : Collision) {
    Debug.Log("OnCollisionEnter");
}

I then created a cube under the ball, added a box collider component with no trigger of course.

Then, when I run the game, the ball falls down onto the cube, but nothing happens. The OnCollisionEnter function isn't called.

What should I do?

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Has the ball a collider attached too? \$\endgroup\$
    – Heisenbug
    Mar 10, 2013 at 12:27

1 Answer 1

8
\$\begingroup\$

I move the comment here, so we can eventually close the post.

Remember that both GameObject MUST have a Collider attached in order the OnCollisionEnter to be called.

As side notes:

  • A MeshCollider cannot collide with another MeshCollider.
  • Even if your colliders as marked as trigger, at least one of the 2 GameObject involved must have a RigidBody attached.
  • Collision between GameObject can be selective enabled depending on the layer the GameObject's belong to. Have a look at Layer-Based Collision Detection.
\$\endgroup\$
4
  • \$\begingroup\$ well, in docs, it says, both of the objects must be rigidbody or collider. In my case, one of them is rigidbody and the other one is collider...and it doesn't works... \$\endgroup\$
    – NamiW
    Mar 10, 2013 at 14:47
  • 2
    \$\begingroup\$ No, it doesn't says "or". Doc says: "When a collision between two Colliders occurs and if at least one of them has a Rigidbody attached, three collision messages are sent out to the objects attached to them." So both must have a collider and at least one of 2 a RigidBody attached. \$\endgroup\$
    – Heisenbug
    Mar 10, 2013 at 14:50
  • \$\begingroup\$ Good bullet points to add: Each object's respective layer must be enabled for collision in the PhysicsManager, and the ability of an object to collide with another is further defined by the collision action matrix at the bottom of this page: docs.unity3d.com/Documentation/Components/… \$\endgroup\$ Mar 10, 2013 at 18:20
  • \$\begingroup\$ @michael.bartnett: good point. I've add it thanks. \$\endgroup\$
    – Heisenbug
    Mar 10, 2013 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .