How does a MeshFilter know what part of a static batched geometry to render?

I was wondering how a MeshFilter knows what part of a statically batched mesh it should pick. Can I use the same functionality on my own meshes → picking and rendering only a part of a geometry.

When objects in a scene get combined with static batching, the MeshFilters of the objects reference one huge “Combined mesh” (that has somewhere around 64k vertices). Yet, when I deactivate one of the GameObjects/MeshFilter/MeshRenderer, I can hide the the part of the combined geometry that was the original mesh.

How does this work?

The static batching feature is internally implemented. Keep in mind that all things that you see in the inspector and that you work with in C# are just wrapper classes. The actual engine is written in C++. The wrapper classes just act as .NET managed interface to engine features.

When an object is marked to be statically batched (either by having “static” checked in the editor or by using the StaticBatchingUtility on runtime generated objects) Unity will actually deactivate the individual renderers and create an internal renderer for each batch.

As you can read in your screen shot the generated combined mesh has 25 submeshes. So the combined mesh shares a common vertex buffer but seperate index buffers. We don’t know how Unity finally handles the rendering of the seperate submeshes. It’s possible that Unity creates a temporary index buffer with only those submeshes that should be rendered (those which are enabled and not frustum culled) or they create a command buffer sequence to issue all required drawcalled at once.

Anyways the exact internal functionality we can not know and we can’t access or modify it. All we can do is tell Unity which objects we want to have statically batched.