[ASK] OnCollisionEnter2D parameter

I am confused between OnCollisionEnter2D() and OnCollisionEnter2D(Collision2D col)
or OnTriggerEnter2D () and OnTriggerEnter2D (Collider2D trigger) .
I don’t see any differences when use the method without parameter. The game still runs smoothly.

Please help me to understand what is the different between the methods with and without parameter?

Hi @mrmt2020,

Which version of Unity are you using?

According to the documentation, for OnCollisionEnter2D at least, you can declare these methods without the parameter if you do not need it. In this scenario, you wouldn’t obviously be able to establish, with any ease, much about the collision - only that it had occurred. I would imagine that if OnTriggerEnter2D works in the same way, then there is an omission in the Unity documentation.

This may be suitable for something like a bouncing ball perhaps, e.g. you don’t care what the ball hits, but when it does hit something you play a “boing” sound.


See also;

Privacy & Terms