- Home /
Bounds of dynamic mesh not updating
I've got a GameComponent that's using a MeshFilter, with a dynamically created mesh, and a MeshRenderer.
As soon as the origin of the object goes off-screen, the mesh stops being rendered both in the game and scene editor views. I'm assuming this is because the bounding box of the object isn't being updated to match the mesh once it gets created.
I've called createdMesh.RecalculateBounds()
, and I've also tried setting it manually, but neither work.
Do I have to set these bounds elsewhere, like on the filter itself, or the renderer, or am I going wrong somewhere else?
Answer by Jesse Anders · Apr 06, 2011 at 12:42 PM
Generally speaking, recalculating the mesh bounds should work. You might try adding some debug output; for example, you could draw the bounding box for the mesh, or simply print its min and max vectors to the console. That should at least tell you whether the AABB has been effectively reduced to a point (which is what the behavior you describe would suggest), or if the problem is elsewhere.
Turns out mesh.RecalculateBounds()does NOT affect renderer.bounds it just always stays at zero. So anyone have a clue what's going on lol.
Edit: Never$$anonymous$$d it does work. But only if called after the mesh is set in the mesh filter. So it's; GetComponent($$anonymous$$eshFilter).mesh = mesh; THEN; mesh.RecalculateBounds();