What is the difference between OnCollitionEnter2D and OnTrigerEnter2D

hello everyone :slight_smile:
i am new to programming and game development and its not so clkear to me what is the difference between OnCollitionEnter2D and OnTrigerEnter2D and when to use each of them…
it would be nice if you can explain it to me please :slight_smile:

thank you

David

Hi David,

Welcome to our community, and thank you for your question! :slight_smile:

The difference between OnCollisionEnter2D and OnTriggerEnter2D is simple: They are two different methods, hence the different names. Furthermore, they are Unity methods. This means that there is already functionality behind these methods. We did not write that functionality ourselves.

In our game, a trigger collider is a collider which has got “Is Trigger” enabled in the component in the Inspector. OnCollisionEnter2D gets invoked automatically if one of the colliders in a collision event is a non-trigger collider. OnTriggerEnter2D gets invoked automatically if one of the colliders in a collision event is a trigger collider. The “Enter” indicates that the event gets triggered if two colliders “enter” one another. For further information, please refer to the manual.

Did this help?


See also:

thank you for your help :slight_smile:
this is helped me to understand why we need this 2 methods and when to use each one of them.
and thank you for the really quick replay :slight_smile:

p.s i really love this unity course
David

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms