Search Unity

Bug SetSubMesh bounds behavior

Discussion in 'General Graphics' started by arkano22, Sep 18, 2020.

  1. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,917
    According to the documentation, calling mesh.SetSubMesh() recalculates the bounds of the sub mesh by default (unless passing MeshUpdateFlags.DontRecalculateBounds).

    This works fine, the descriptor.bounds field is updated. However, mesh.bounds does not seem to. If you do:
    Debug.Log(mesh.GetSubMesh(0).bounds.extents);

    Correct bounds extents are printed to the console. But if you do:
    Debug.Log(mesh.bounds.extents);

    the extents are always zero, unless you call mesh.RecalculateBounds(). How come recalculating bounds for a sub mesh does not update the mesh bounds? Really looks like a bug...is this intended behavior? What's the point of recalculating bounds for a sub mesh if we need to recalculate the entire mesh bounds afterwards?
     
  2. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    Ran into the same issue, but I was passing the DontRecalculateBounds flag while passing in a correct manual calculated bounds. I suppose this makes *some* sense, since you're setting a submesh which may not mean you want to set the 'main' mesh.

    Would definitely like the docs to be updated to include this difference, had to also assign the bounds to mesh.bounds.
     
  3. paddan

    paddan

    Unity Technologies

    Joined:
    Jun 19, 2019
    Posts:
    13
    Hello,
    This could indeed be a bug or an issue with documentation. Please file a bug report clearly describing your expectation versus the actual result.
     
  4. Jebtor

    Jebtor

    Unity Technologies

    Joined:
    Apr 18, 2018
    Posts:
    115
    We hope to address and improve this behavior in the future. For the time being please use Mesh.RecalculateBounds(). I have updated the documentation to reflect this gotcha. There is also an item on the issue tracker here. Once the work has done the issue should get resolved as Fixed. Until the work has started the issue will be listed as postponed.
     
  5. TJaenichen

    TJaenichen

    Joined:
    Oct 12, 2014
    Posts:
    29
    Running into this now. I hope this is getting fixed. It's a huge hit on the performance have to do RecalculateBounds in the main thread.