OnTriggerEnter2D() function not working

I have a player object that has a box collider 2d and a rigid body 2d, this is set to simulated and to dynamic. Then I have another object that has a box collider where is trigger is ticked, I have also added a rigid body 2d to this object, however, I don’t think it actually makes a difference if I have it or not. (both rigid bodies are simulated and dynamic) Then on my player character, I have the code :

  private void OnTriggerEnter2D(Collider2D col)
        {
           if(col.gameObject.tag == "Box")
            {
                Debug.Log("No");
          }
        }

The weird thing is if I get rid of the if statement then the console writes out No, so doesn’t that mean that all the box colliders and rigid bodies work? I’m new to unity so I have no idea. I hope someone can help a fellow new beginner out :slight_smile:

Hi!

first of all, have you set the “box” gameobject a tag called “Box”? that’s the most common mistake.

Second, you shoudn’t use that way to compare a tag, instead use

if(col.gameObject.CompareTag(“Box”))

this approach is better cause is faster, mostly if you check a lot of collisions

Hope this helps! Good Luck!