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) ?

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.

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.