Hi everyone,
I’m using Unity 6, and I’ve noticed that the Collider.excludeLayers
property does not work at all. For example, even if I set excludeLayers
to exclude a layer like “Enemy,” the Collider still interacts with objects on the “Enemy” layer. The exclusion simply doesn’t happen.
Here’s what I’ve done:
- I created a layer named “Enemy” and assigned it to specific GameObjects.
- In my script, I set the
excludeLayers
property like this:collider.excludeLayers = LayerMask.GetMask("Enemy");
- Despite this, the Collider continues to detect and interact with objects on the “Enemy” layer as if the exclusion wasn’t set.
This behavior was not an issue in previous versions of Unity, where the excludeLayers
property worked as expected. It seems to be entirely broken in Unity 6. I’ve double-checked the following:
- The Layer Collision Matrix in the Physics settings is configured to allow the layers to interact (so it’s not a global collision filter issue).
- I’ve confirmed that the
excludeLayers
value is set correctly in the script and applied to the Collider.
Is this a known bug in Unity 6, or has something changed in how excludeLayers
is supposed to function?
Has anyone experienced the same issue or found a workaround?
Thank you for your help!