onEnterCollision2D not working when objects collide

Hey! So i just recently asked a question about my objects not colliding and found out that I should be using rigidbody2D instead. After changing it I wanted to use onEnterCollision2D to tell when it hits something.

        void onCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("Hit");
    }

However when I attach this to my Player object, my console stays blank and nothing else happens. Ive tried changing it to

        void onTriggerEnter2D(Collision2D collision)
    {
        Debug.Log("Hit");
    }

while also toggling “is Trigger” on my Player object and nothing happens still. I’ve attached a Boxcollider2D and a Rigidbody2D to both objects and even though they clearly collide and physics happens, the console still stays blank.

this is a pretty close question to my last one so I apologize for somewhat asking it again, but I’ve watched about 10 different tutorials that all have these same exact codes working just fine.

This is my Object

And this is my Player

Thank you so much, and if there is any more information I can provide just let me know.

You need to be careful and use the correct case for method names. It’s “OnCollisionEnter2D” (not an initial lowercase ‘o’). C# is case sensitive so your method is a completely different one that Unity doesn’t call.

This applies to your trigger method and any other method that Unity calls too.

1 Like

So im not gonna lie, Ive been struggling with this for about a whole day or so. I fixed the “O” and it works!! Your a great help man, I really appreciate it. Now I gotta kick myself for it being such a simple fix lol

1 Like