You can see Batching working in the Stats window when the “Saved by batching” count is greater than zero. But unfortunately it is much harder to tell why Batching is NOT working. The Unity Manual provides some information about why this might be happening, though you have to rely on an educated guess based on that information.
Fortunately, Unity 5.6 adds a new feature to the Frame Debugger which says exactly why Unity started a new batch.
Frame Debugger is a window in Unity which shows every batch in your game along with additional details about shaders, textures, and numerous settings used in a batch. The Frame Debugger window can be opened from the Window > Frame Debugger menu and has been available since Unity 5.0.
Before digging deeper into cases when Unity starts a new batch, let’s talk about what batches and batching are.
To draw an object on screen in your game Unity needs to issue a “Draw” command to the graphics API. This action is essentially called a “Draw Call”. But before doing this, Unity also needs to set all the GPU states required to draw this object: mesh, shader, textures, blending settings and other shader properties. State change commands plus one or more draw commands is what we call a Batch.
What makes a batch slow is the GPU state change commands, while draw commands are actually pretty cheap. This is why Unity tries to pack several objects being rendered using the same GPU state into one batch. This process is called Batching.
Unity has three types of batching: static batching, dynamic batching and GPU instancing.
Sometimes you can clearly see in the editor that objects you expect to be batched, for some reason, are not. First of all, check if batching is enabled in Player Settings. It sounds silly, but you won’t believe how many support requests we’ve received where this was the culprit.
Especially for you, we’ve prepared a sample project which illustrates all the cases when Unity has to start a new batch. Please clone it to your machine to follow along. Note that you need Unity 5.6 with the updated Frame Debugger to see the batch breaking causes illustrated in this project.
Here are batch breaking causes from the sample project (as of Unity 5.6). Each says why the object being rendered is in a separate batch:
Now you can use this new exciting Frame Debugger feature in your project and see if there’s something you can do with your scene to improve how Unity batches objects.
Please follow the project on Github for updates if new batch breaking causes are added as the engine evolves.