Collision2D not working

I followed a snake game tutorial and am trying to make it die if touches itself. For that I made a Tag for the new parts of the snake body as “Body” and wrote:

  void OnCollisionEnter(Collider2D coll)
    {
        if (coll.gameObject.tag == "Body")
        {
            Debug.Log("fj");
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }

    }

For some reason this does not work, however if I set the collider2d as Trigger and add it to my OnTriggerEnter function, it works like a charm.

Are there any rules for OnCollisionEnter that I am not doing right?

You need to use OnCollisionEnter2D

Try coll.collider.gameObject.tag

Uncheck the isTrigger flag on the Collider component, solved the problemfor me(if you are using
OnCollisionEnter2D).

- If that didn’t work for you try doing these:

  1. Change the Body type to Dynamic and not kinematic if you have a Rigidbody2D.
  2. Check the Zee position of your spawner, source object,target object. Make sure that they are on the same Zee because otherwise they wont collide obviously.
  3. Check that your script and class names match.