- Home /
Performance difference between OnCollision and OnTrigger messages?
How much real difference is there?
The unity reference says "leave out the collisionInfo parameter as this avoids unneccessary calculations", but what does it really mean by collisionInfo parameter? http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html
I am assuming if I don't access the contactPionts and relativeVelocity properties of the Collision class there's not much of a difference? (as each of them are going to be a function call that cost some heavy calculation...)
Am I getting this right?
Answer by Skjalg · Apr 11, 2011 at 09:13 AM
It is referring to the fact that you can create two kinds of OnCollisionEnters in your MonoBehaviour. The Costly One:
void OnCollisionEnter(Collision collision)
{
Debug.Log("Collided!");
}
... And the Low Performance:
void OnCollisionEnter()
{
Debug.Log("Collided!");
}
The second one is low performance, because the Unity3d engine doesn't need to do a lot of calculations for you in order to provide the Collision parameter :)
Thank you very much for helping!! I didn't know that you could omit the entire parameter. O.o||
But does that mean once the collision parameter is included, everything must be calculated and at maximum cost? Even though all I need is just the collision.gameObject.name...
Because that's 99% what I need to know, the object that is colliding with....
I know this is an older thread but I wanted to add you can do a lot for performance by isolating the layers of objects that will collide by setting up those relationships in the Edit->Project Settings->Physics menu. This will $$anonymous$$imize the noise you're getting if you're only really looking for specific physics collisions.
Answer by benjaminw · Jul 04, 2013 at 10:08 PM
If all you need to know is what the other object was you can make one or both of them Triggers and use OnTriggerEnter(Collider). You can use the Collider to get at the game object that's doing the colliding with the trigger.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122019im_/https://answers.unity.com/themes/thub/images/avi.jpg)