Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Physics methods use collision matrix despite being passed a layer mask

Discussion in 'Editor & General Support' started by KelsoMRK, Apr 11, 2014.

  1. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    We noticed in our latest build that after awhile we were getting very poor performance as a result of Physics.Simulate(). The issue has largely been alleviated by turning a majority of the collision matrix off however this appears to have broken some of our Physics.OverlapSphere calls. I'm wondering if this behavior is intentional and a result of the actual Physics calculations using the Physics API.

    Our game world is organized using empty GameObjects on the Default layer.
    World Parent
    - Terrain Parent
    --Terrain...
    - Unit Parent
    -- Unit....
    - Building Parent
    -- Building

    Our units can either be inside or outside a building and will swap their layers depending on that state. We use OverlapSphere to check for nearby "things" (props, enemies, cover points, etc). There are layer masks set up for these checks so exterior units will only check for exterior things and interior will only check for interior.

    These checks broke after unchecking Default in the collision matrix. It would appear that OverlapSphere is, at least partially, being treated as a real collision. Both the unit and the "thing" are children of the same GameObject (WorldParent) so some part of the evaluation is bubbling up to WorldParent which is on the Default layer. Because the matrix is not checking the Default layer the OverlapSphere check returns no Colliders despite the layer mask checking for the correct layers.

    This doesn't feel like the correct functionality to me. If I'm explicitly telling the method what layers to check why is it referring back to the matrix at all? Also, if the Collider being returned is the "thing" on the exterior layer why is some part of the evaluation looking at the fact that WorldParent is on the Default layer?

    I've confirmed that enabling the Default layer appropriately in the collision matrix fixes the issue.

    Thoughts? Is this a bug?
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Bumping to see if anyone has any reasons why this works this way.