Mesh disappears in Scene View

I have some code which generates a mesh at run time. I have attatched my mesh to an object with a MeshFilter and a MeshRender and it is showing in the Scene, but if I change the view (by zooming or panning) so that the pivot of the object is not in the Scene View then the whole mesh disappears. This makes it impossible for me to zoom in on any part of the mesh but the pivot, which is very annoying.

Strangely enough, if I rotate the object the problem goes away and it doesn’t return even if I undo the rotation. This is a workaround but an annoying one.,

Sounds like a bounding box issue:

after generating the mesh, try calling mesh.RecalculateBounds(); explicitly.

2 Likes

I am doing this already but it doesn’t seem to work. When I print out mesh.bounds, it shows:

Center: (115.5, 67.0, 0.0), Extents: (145.3, 109.8, 0.0)

which is what I would expect.

Have you found the solution?

In my minecraft-like engine I combine multiple boxes into 16x16x16 chunks using CombineMeshes function. When I create a chunk gameobject and assign a mesh to it for the first time, everything works fine, the chunk is always visible when it should be. But if I later assign a new mesh to the same object, its visibility switches absolutely the same way as if nothing had changed at all.

This screenshot shows a chunk with two sets of blocks: the original ones on the right, and lately added ones on the upper left.

When the older blocks go out of the screen, the whole chunk disappears:

I checked Mesh.bounds and MeshRenderer.bounds - they are always correct, there’s even no need to call Mesh.RecalculateBounds in my case.

gameobject.active = false;
gameobject.active = true;

These two lines update whatever need to be updated and the visibility problem goes away.

Have you marked the GameObject static perhaps?

go to import settings for your mesh and make sure it isn’t at 0.01 which is default.

Man you made my day: this was my problem. I had to just call RecalculateBounds over the mesh that I calculate every frame. It looked like a regression since the time I moved from creating a new mesh object every frame, to just update its vertices.