OnTriggerEnter2D not called after collision (2D game)

I’m brand new to Unity and I’m having issues with my first collision detection. My moving object is a ball and has Rigidbody2D and CircleCollider2D. My stationary “collider or trigger” is a BoxCollider and has a script attached. The OnTriggerEnter2D should be fired when the ball passes through the stationary box. I’ve also tried OnCollisionEnter2D but I’m fairly certain I should use OnTriggerEnter2D because my stationary box is marked as a trigger.

My code:

public class LoseCollider : MonoBehaviour {

    public LevelManager levelManager;
	
    void OnCollisionEnter2D(Collision2D collision)
    {
        print("collide");
        levelManager.LoadLevel("Lose");
    }

    void OnTriggerEnter2D(Collider2D trigger)
    {
        print("trigger");
        levelManager.LoadLevel("Lose");
    }
}

And screenshots of my 2 object properties:

Ball:

Collider:
93060-collider.png

I made sure to keep them on the same Z plane, so I’m fairly certain the objects ARE colliding. I just must be missing something simple in my properties or something. Any help is appreciated.

Hi, I’m new to unity also, try the following code in your boxscript 8,-))

void Update () {
		
	}
    public void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("we are in the trigger");

    }
    public void OnTriggerExit2D(Collider2D collision)
    {
        Debug.Log("we have left the trigger");
    }
}

make sure the ball is set as not a trigger and that the box with the script is set as a trigger, I hope this Is of some help too you, have fun 8,-))

Matt.

Hey thanks. I just figured it out and it seems I added a “Box Collider” to my object instead of a “Box Collider 2D”. Once I swapped it out everything worked as expected. :slight_smile:

Thanks