OnCollisionEnter2D NOT WORKING

Hi, I am trying to make two circle collide between them, and detect the collision in a script receiving a Debug.Log in the console. Each of them has a Dynamic Rigidbody2D and a CircleCollider2D components. When the two circles collide, the collision response from the physics engine is correctly made, but in the console nothing appears.

Here’s my code:

public class mandc : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        GetComponent<Rigidbody2D>().velocity = new Vector3(0, 1, 0);
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("OnTriggerEnter2D");
    }

    private void OnTriggerStay2D(Collider2D collision)
    {
        Debug.Log("OnTriggerStay2D");
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("OnCollisionEnter2D");
    }

    private void OnCollisionStay2D(Collision2D collision)
    {
        Debug.Log("OnCollisionStay2D");
    }

}

9223905--1288011--Contacts.png

Assuming you’ve not simply turned off the display of info-message in the Console window itself, the only reason a callback won’t happen if you’ve got a collision response is if you’ve changed the Callback or Contact Capture Layers in the “Layers Override” foldout. By default they’ll be “Everything” so you’ll get callbacks.

I realized that before I turned off the logs in the console to look for an error message. Now it works. Thank you, MelvMay

1 Like