Why Does Reducing Meshes Increase Batches?

I’m trying to reduce memory and improve performance, and I think one possible issue is too many separate meshes in my scene. I took one object that was made up of about 20 separate child-object meshes, and I combined them (in my 3D modeling program) into just 5 meshes. They all share one material. There are 4 instances of this object in the scene, and it is non-static (it has some moving parts). That means I went from over 80 separate meshes (across the 4 instances) to 20 total, 5 each. Some of the Profiler numbers changed as expected, they stayed the same or decreased, but not all (see below). Why did the number of batches increase? Why would there be 10 more batches? If I reduce the number of meshes for more objects in the scene, will the batches keep going up, and everything else keep going down? Isn’t combining meshes that share the same material a good thing?

The first number is for the original object with 20+ separate meshes (x4), the second is after I combined meshes.

Batches: 158 168
Tris: 251 251
SetPass Calls: 37 37
Textures: 590 590
Meshes: 17476 17405
GameObjects in Scene: 7584 7110
Total Objects in Scene: 31150 29343

Following, as im curious too. The displayed results have often left me baffled.

The Frame Debugger might answer your question about the additional batches.

The rules regarding exactly what order your GameObjects are rendered in are a little vague (although they tend to be closest-to-most-distant for Opaque renderers, and most-distant-to-closest for Transparent renderers), but making changes to your scene will alter the order. It is rather odd to increase the number of batches when reducing count though.

Were both of these measurements taken at the exact same camera position and angle? Because of the above, the number of batches being drawn is totally dependent on your current camera position. Shift the camera by 1 degree or move it by a world unit and your batch count may change.

Yes, everything is identical between measurements – same scene, same objects in scene, same camera position/rotation/FOV. I’ve repeated the measurements a few times, switching back and forth between the two versions of the model, always the same result. Also I forgot to mention, dynamic batching is turned on.

If meshes and game object counts go down, does that translate to less memory used? If batches goes up, does that mean performance is reduced? I don’t want to continue cleaning up the rest of the models in the scene if it’s having the wrong effect. The bottom line is, am I making things better or worse by combining meshes?

FWIW, my main concern is memory. Performance is acceptable, 60 fps on newer iPhones and iPads, but I’m getting low memory warnings on older iOS devices.

I just noticed, I must’ve signed in with an old, unused ID for the original post (damn autocomplete). I’m the original poster.

One possible scenario is if you’ve merged a few meshes that cover a large area, or it’s somehow effected your lighting. Fire up the Frame Debugger and check what it’s saying - it’s very good for determining the root cause.

Off the top of my head, can’t really figure out how reducing the number of objects would increase the batch count that much - but any change to the draw order can reshuffle things in unexpected ways.

However, 160 batches is very nice for 17405 objects, regardless.

The number of batches have almost nothing to do with memory usage as such - they are specifically performance. Unifying your meshes also isn’t a huge benefit (although mesh compression may give you small memory usage bumps when you combine them). What you’ll be most concerned about are the number of textures and meshes loaded. Best approach is to reuse meshes where possible (which you probably do) and reduce texture resolution.

The Frame Debugger was a mixed bag for me. Lots of information about how meshes are combined into batches, but it’s not always obvious (to me) why or why not. For example, my test objects — 5 child meshes each x 4 instances in the scene — are drawn piecemeal. Different meshes from different instances are combined into batches. I have no idea why those batches are divided up that way or how to change or improve it.

So I decided to go ahead and clean up the rest of my models, which was quite a job since combining meshes breaks prefabs. The results after all possible meshes were combined and a few unnecessary polygons were removed are shown below. The changes are significant.

What I found was that combining meshes had an inconsistent effect on number of batches — sometimes batches would go up, sometimes down or no change — though overall, batches did decrease. The other numbers changed as expected, consistently going down. SetPass calls remained the same.

This has made it obvious to me that number of meshes is only one factor determining how the meshes are combine into batches. It’s generally good to reduce meshes, but other factors (e.g., camera position, where objects are located in the scene) can sometimes mask the effect. I have yet to build and run on iOS, I’m a bit afraid that after all this, there’s going to be no improvement in the actual app.

Batches: 117
Tris: 233
SetPass Calls: 37
Textures: 546
Meshes: 5080
GameObjects in Scene: 1968
Total Objects in Scene: 8788

I’m not sure why there’s over 500 textures. There aren’t that many in the entire project. I’d guess there are not more than 30-40 materials in this scene.

The point of combining meshes was to reduce the number of meshes. I’ve already gotten the number of materials and texture sizes down to their bare minimums.

What do you mean by reusing meshes?