[SOLVED] OnCollisionEnter2D Not working??

So this is not my first time using this function, I’ve used it 100s of times with ease. But it’s been a couple months since I’ve worked with Unity and am starting a new project now. First time I go to use it, it doesn’t work.

I am not getting any error. It just simply isn’t working. My code:

function Start ()
{

}

function Update ()
{

}

function OnCollisionEnter2D (colsn : Collision2D)
{
     print ("It is working!!");  // This does not trigger PERIOD
}

I made the above script as BASIC as possible to ensure nothing was interfering and it still refuses to work. Nothing happens at all.

I drag it through objects with colliders on them making sure it is passing through the collider.

The object with the above code attached has a Box Collider 2D on it that is NOT a trigger. None of the other colliders are triggers.

What is going wrong?

PS: Using Unity 5.6.1f1

EDIT: I have tried having the same script attached to other objects involved in the collision and that does not change things. For some reason, collisions are not being registered at all.

EDIT II: I have also tried the other collision types (OnExit and OnStay) and have tried a variety of colliders. Nothing fixes it.

Any help would be greatly appreciated!

SOLUTION!

I forgot to add a Rigidbody2D to one of the objects involved in the collision. All objects involved in a collision must have a Rigidbody attached!

- Chris

Have you got at least one rigid body involved in the collision?

1 Like

I think, but can’t recall, that for the 2d you still have to have a 2d rigidbody attached to one of the objects. But not sure if this is correct for the 2d stuff.

1 Like

THANK YOU for reminding me that BOTH objects need a Rigidbody2D attached! I only had a Rigidbody on one of the two involved in the collision and forgot to add it on the other!

That is correct. Each object involved in the collision must have a Rigidbody2D on it.