- Home /
Remove collider vs putting on a layer that ignores collisions
For the cases below, is there a performance difference to either removing a collider or just putting it on a layer that ignores collisions?
Case 1: You only need to remove the collider at runtime
Case 2: You need to remove the collider and add it later at runtime
Actually, I am still not sure if I understand using layers for such things - I guess the built-in functionality only makes it simple if you want to ignore script-initiated raycast (but not actually ignore collisions among objects) ?
Answer by DoktorAce · Apr 25, 2012 at 09:17 AM
I've been doing some research about this for a project at work. I wanted to see which method was fastest. All tests were done in the exact same scenario and fashion. Please note that the values below are from my test case and does not reflect each individual method, but rather how they performed in my scenario.
Please note that if we are talking about a trigger, this best way is to handle that in its behavior. Something in the line of having a bool check in OnTriggerEnter, end never touch the collider. That would have no impact at all.
Answer by dannyskim · Jan 24, 2012 at 11:25 PM
Can you explain your scenario a little more in depth? I would think by using the Unity provided layer collision matrix to ignore collisions would be faster, but I don't think it offers any kind of appreciable performance enhancement if you're just removing a primitive collider. Removing a complex or compound collision box would probably be much slower though, you would have to iterate through a block of colliders to get the task done.
I've used Physics.ignoreLayerCollision( int layer1, int layer 2, bool ) with great success. From my experience, when you ignore the layer collision at runtime with this method, you have to call it again or reset it yourself. The hint this in the documentation as well.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Ignoring collisions between a layer and a single object 0 Answers
What drawback of frequently changing of Game Object's Layer? 0 Answers
Collision functions without physical collisions 1 Answer
Layer Collision issue 1 Answer
Layers are colliding even though they are set to ignore each other 1 Answer