- Home /
Physics.OverlapBox colliding with disabled MeshCollider
I'm using this:
Collider[] cols = Physics.OverlapBox(worldPos, new Vector3(1.39f, 1.39f, 1.39f), Quaternion.identity, BuildingData.buildingMask);
to look at an area. It always works and has for days, but I've found that if I have a disabled MeshCollider on one of my walls (built using ProBuilder) it triggers the OverlapBox even though the collider is off. This is of course undesirable, and is why I turn the collider off in those cases (dummy wall that gets moved around before placement, half-transparent, all colliders disabled).
If I remove the MeshCollider completely it stops throwing the error even though there is a BoxCollider the exact same dimensions/position that never hits while disabled.
Logically I want to assume it's something wrong with the way ProBuilder is handling the collider, but it shouldn't matter when it's clearly disabled... should it?
You are right, it shouldn't matter. All Pro Builder does is generating a bunch of vertices that form a mesh. The physics engine is only told to use it. Have you tried logging the enabled state after you detect the overlap? I bet it's enabled.
I use pause on error so I'm just looking at the object when the error is thrown. Hmm... I will try it anyway, maybe it's being turned off simultaneously.. There's a chance it's being brought in and turned off in the same frame the check it happening. I have seven or eight other objects all with colliders being turned off in the same manner though that have never caused problems. Just this one $$anonymous$$eshCollider...
I'm getting a False return from Debug.Log(cols[0].Enabled.ToString()); There's no way that's correct. The line after the collider is taken in for the precise reason of being collided with it then reports itself as disabled. Can't seem to reproduce it of course... and I worked around it by removing the collider so it's not hindering me anymore... still certainly not "working" behavior
Answer by $$anonymous$$ · Dec 04, 2019 at 08:55 AM
i think Physics.OverlapBox doesn't get the mesh collider because it doesn't "exist". make the mesh collider always active and set it to "IsTrigger" and in the Physics.OverlapBox set the Query Trigger Interaction to QueryTriggerInteraction.Collide.