OnCollisionEnter() function isn't being called

I am trying to detect a collision between a knife and a cube, but OnCollisionEnter() never calls when the knife intersects with the cube.

 private void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.tag == "Knife")
        {
            camera.OnCollisionWithKnife(collision);
        }
    }

The knife has a mesh collider and it is set to “is trigger”, the cube has a box collider and a rigidbody that is set to not kinematic. The OnCollisionEnter() is attached to a script component of the cube, am I doing something wrong?
the objects clearly collide (as seen in the screenshot):

and the tag doesn’t matter because the function OnCollisionEnter() isn’t even being called.

    private void OnTriggerEnter(Collider other)
    {
       
    }

Is the code you’re looking for. Check out the collision matrix here:

If the above still doesn’t help, then:
Edit → Project settings → Physics
Make sure the layers have collisions enabled.

Using OnTriggerEnter() solved it :slight_smile: It still requires a rigidbody for some reason, and I’m not sure why OnCollisionEnter wasn’t working but I’ll read the manual, thank you!

For collision enter, you’d need either a static non-trigger collider, and rigidbody on the other object, or you’d need a rigidbody on both of the objects.

1 Like