What is the difference between MonoBehaviour.OnCollisionEnter2D and Collider2D.OnCollisionEnter2D?

Hi! i am new to Unity, so my apologies if the question is sort of naive and not worth your time, but i would really appreciate if someone could answer it.

In the online documentations of Unity i have read two OnCollisionEnter2D methods one is Monobehaviour.OnCollisionEnter2D and the other one is Collider2D.OnCollisionEnter2D, Now i know that you can use the first method if the script is inherited from Monobehaviour and the other one if you have a collider2D component on the gameobject. But why are there two of these?

And if two objects collide with each other who’s OnCollisionEnter is called, and which of the above is it?

Thank you!

-Hashim

Those two are literally the same methods. As you can see on the doc. of Collider2D OnCollisionEnter2D is just a “message” that is send to any script (MonoBehaviour) that is attached to the same gameobject. The MonoBehaviour documentation just lists most messages it can receive from other components.