Two box colliders not causing OnCollisionEnter to fire?

Maybe I’m missing something dumb but I have two box colliders, on two different layers.

I have the following code attahced to one of the gameobjects that contains a box collider, but this method never fires when the two colliders interact.

void OnCollisionEnter(Collision col) {
  // Code here for collision, but this method never fires
}

1.) I have checked the collision matrix, both layers are set to collide with each other
2.) One of the colliders has a rigidbody attached
3.) The colliders are not set to be triggers.
4.) I’ve tried modifying the layer overrides, no difference.

Am I missing something?

I can only ever get it to fire with OnTriggerEnter, by marking my one object as a trigger. But otherwise can never get OnCollisionEnter to fire.

Thanks

  1. neither collider is an ancestor of the other,
  2. the rigidbody is dynamic, isKinematic=false,
  3. the behaviour expecting OnCollisionEnter is on the same object as the rigidbody,
  4. the rigidbody’s motion is only via physics, e.g., MovePosition or velocity or AddForce
1 Like

Thanks, I’m guessing #7 is where I’ve got it wrong…

My OnCollisionEnter is not on the same gameObject as the rigidbody, the rigidbody is on the other object that receives the force of the collision.

The script that handles OnCollisionEnter doesn’t need to be on the rigidbody.

It does, I’ve just fixed the issue by moving the script onto the gameObject that has the rigidbody component.

Strange… I wonder if they’ve changed something in later versions. In version 2021.3 I don’t need to have a script present on the rigidbody.

Possibly, that’s why I was so confused lol

You can have the script on the collider that has the dynamic Rigidbody as an ancestor, but putting a script on a non-Rigidbody-backed collider is not going to reliably be informed of collisions.