- Home /
mesh from scratch disappearing if transform out of view
I am creating a plane mesh through code using this function: https://gist.github.com/952795
For some reason when the transform point of the game object moves out of camera view, the entire mesh isn't rendered. I know the bounding box info is being updated by seeing the Debug.Log info.
Answer by Eric5h5 · May 03, 2011 at 04:49 AM
Try doing RecalculateBounds after assigning the mesh, rather than inside the function that creates the mesh.
I tried everything, but ended up abandoning it for a mesh created in a 3D app. I'd still like to know why it behaves that way though. Perhaps it's a bug.
Answer by Gillissie · May 03, 2011 at 05:55 AM
Eric5h5, you were on the right track. It turns out that you have to call RecalculateBounds() on the mesh AFTER assigning it to the mesh property of the MeshFilter component. Apparently it doesn't take the bounds values with it, which seems like a bug (I'll report it).
Right, but you weren't specific to calling it on the $$anonymous$$eshFilter.mesh. I also tried calling it on the mesh outside the function, but only on the returned mesh before assigning it to $$anonymous$$eshFilter.mesh. Oddly, doing it that way set the bounds correctly (as proven by using Debug.Log), but it strangely isn't honored by the renderer. I have submitted a bug report with a complete project to reproduce it.
To be more specific, this doesn't work properly:
mesh = createPlane(10,10,4); mesh.RecalculateBounds(); GetComponent($$anonymous$$eshFilter).mesh = mesh; // or do mesh.RecalculateBounds(); here, doesn't matter. Actually at this point, GetComponent($$anonymous$$eshFilter).mesh.bounds will show the correct values, but the rendering issue happens.
I did say "after assigning the mesh"; by that I was referring to "GetComponent($$anonymous$$eshFilter).mesh = mesh" (I've had to do this before). Anyway, glad you got it working.