Objects belong to different static batches

I notice that when batching some static GameObjects that all use the same sharedMaterial, I tend to receive the following batching issue:

“Objects belong to different static batches.”

While so far this only adds 1 extra draw call, I am finding it really odd and would love to solve the problem.

The only difference I can spot between the 2 objects, is that they get split between two different generated combined meshes.

These 2 objects are identical, except for their parents and transform.position. They come from a prefab. Instantiate is done by just having them exist in the scene’s hierarchy.

I presume the fix here is to somehow control which combined mesh they become a part of?

Yes, but there isn’t any control over that apart from giving them the same unique material and essentially assign what meshes you want to batch together with that unique material (and even then Unity isn’t guaranteed to batch them). It’s possible you just have enough meshes being statically batched that Unity needs more than one mesh to hold them all. Pre 2017.3 Unity is limited to 16k 64k vertices per mesh, static batch or otherwise.

Even since adding 32bit index support in 2017.3, static batches won’t exceed 64k vertices, because 1 batch with wider index buffers is not expected to be more efficient than a small number of separate batches, each with 16bit indices.

32bit index buffer support is mainly for convenience when dealing with large meshes where you would otherwise be forced to manage multiple meshes yourself.

2 Likes

Ah, okay. Thanks for the info.

Can someone add this to the static batching docs? Took me some time to find this and the answer, why my batches are still so high even in 2017.3.

1 Like

Will do! :slight_smile:

1 Like

Hey all, I have to post a retraction!! :frowning:

I’ve just been double-checking the code, before adding this info to the docs, and it seems like static batching does support 32 bit indices. So, if you’re seeing a case of it not working, please submit a bug report, and we can investigate properly.

Sorry about that!

2 Likes