Child Collider behavior driving me crazy. Is this a bug?

Ok so. This is some wonky so I’ll try hard to explain it simply.

  • You have a GameObject with a script called CastScript and a MeshCollider
  • If you raycast from the CastScript it will find the MeshCollider on the GameObject that it is attached to
  • If you then do a MeshCollider.enabled = false and raycast from the CastScript, it will no longer find that MeshCollider on the same Gameobject

Now, all that is expected.
This is where its driving me crazy.

  • You have a GameObject with a CastScript on it
  • As a child of GameObject you have ChildGameObject, on ChildGameObject is a MeshCollider
  • Now you if you ray cast from CastScript it will find MeshCollider
  • if you then do MeshCollider.enabled = false, then raycast from the CastScript it will still find MeshCollider on ChildGameObject

Why is it that if you Raycast from a script, it will find the MeshColliders on the children of that scripts GameObject even if those MeshColliders are not enabled?

Is this a bug? Or is this intended and I’m missing something?

this is happening to me too.
I have a simpler version:

I have a meshCollider that I don’t want a raycast to hit.
So I MeshCollider.enabled = false (in the inspector);
I do the raycast.
raycast still hits it.

I even Debug.Log to make sure that hit.collider.enabled == false

By Design?

thanks in advanced.

EDIT: I worked around it by putting the collider I wanted the raycast to hit into a unique layer, performed the raycast and then pulled it back out of the unique layer.

I hope this helps somebody else =)