Search Unity

SphereCastAll hitting inactive colliders; is this a bug?

Discussion in 'Physics' started by rageingnonsense, Dec 17, 2015.

  1. rageingnonsense

    rageingnonsense

    Joined:
    Dec 3, 2014
    Posts:
    99
    I am experimenting with chunked LOD terrain. Each of my chunks uses a meshcollider. As such, there are always overlapping chunks (for the different levels of detail), but only ever one active at any point in time.

    When I perform a SphereCastAll call against my terrain, I am getting hits for chunks that have their meshcollider components disabled.

    Is this behavior defined? I can't find anything in the docs that say this should be happening, and I was unable to find anything related to this via a google search. I expected SphereCastAll to ignore colliders that are disabled, but it is behaving as if they are active!

    The gameobjects themselves are not disabled, just the meshrenderer and meshcollider components.

    Is there something I am missing? Is this actually what it is supposed to do, or is this a legitimate bug? To me, this seems like a glaring bug.
     
  2. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    The docs say that this method "Casts a sphere against all colliders in the scene" Now, like you I would have assumed that this should only work against active colliders, but the letter of the docs says otherwise.

    One of the Zen rules of Unity that have served me well so far is "don't dwell, move on." The method is working consistently if not intuitively. Accept that and go with it. If you must, you can move the inactive colliders into their own layer and exclude them using a layer mask.

    HTH
     
    Last edited: Dec 17, 2015
  3. rageingnonsense

    rageingnonsense

    Joined:
    Dec 3, 2014
    Posts:
    99
    Yeah it is rather odd behavior. I think Unity physics is far too focused on collision events (OnCollisionEnter, etc). Disabling a collider just disables that event from firing. Personally, I think it should disable it in all ways. Why would one need to ever detect a collider that is disabled?

    Anyways, you are right; I shouldn't dwell on it. fortunately this is one of those things that CAN be worked around. I just place the object on the "Ignore Raycast" layer in all places where I disable the collider, which does what I want.