OnCollisionEnter2D doesn't display debug message

I have two characters who currently collide. The thing is, when they collide, the debug message doesn’t show up. They both have rigidbody2D and box colliders 2D. Is trigger and is kinematic is turned off. gravity scale is set to 0.

void OnCollisionEnter2D(Collision2D other)
        {
            if (other.gameObject.tag == "wallX")
            {
                Debug.Log("HIT!");
    
                //this.transform.rotation = Quaternion.LookRotation(moveDirection);
            }
    
            else if (other.gameObject.name == "background")
            {
                Debug.Log("HIT!");
    
                //this.transform.rotation = Quaternion.LookRotation(moveDirection);
            }
        }

Please help me.

  • How you are moving your rigidbody, if moving in Update method with transform.position or Translate method then probably your are missing your collision
  • Either your tag comparison is getting failed or your gameobject doesn’t even have any tag
  • Or your gameobject name comparison is getting failed