Dynamic batching has the following three important qualities:
Batches are generated at runtime (batches are dynamically generated)
The objects that are contained within a batch can vary from one frame to the next, depending on what meshes are currently visible to the Main Camera view (batch contents are dynamic)
Even objects that can move around the scene can be batched (it works on dynamic objects)
These attributes lead us to the name Dynamic Batching.
If we return to the Player Settings page and enable Dynamic Batching, we should see that the number of batches drops from nine down to six. Dynamic Batching automatically recognizes that our objects share material and mesh information and, therefore, combines some of them into a larger batch for processing. We should also see a different list of items in the Frame Debugger, demonstrating that meshes are now being dynamically batched:
As we can see from the Frame Debugger, our four boxes have been combined into a single draw call named Dynamic Batch, but our four spheres are still being rendered with four separate draw calls. This is because the four spheres do not fit the requirements of dynamic batching, despite the fact that they all use the same material. There are many more requirements we must fulfill.
The following list covers the requirements to enable dynamic batching for a given mesh:
All mesh instances must use the same material reference.
Only ParticleSystem and MeshRenderer components are dynamically batched. The SkinnedMeshRenderer components (for animated characters) and all other renderable component types cannot be batched.
There is a limit of 300 vertices per mesh; however, the total number of vertex attributes used by the shader must be no greater than 900. This means that for complex shaders, the maximum number of vertices per mesh may be less than 300 (see the Vertex attributes section for more details).
The objects must not contain mirroring on the transform (that is, a GameObject A with a positive scale and a GameObject B with a negative scale cannot be batched together).
Mesh instances should refer to the same lightmap file.
The material's shader should not depend on multiple passes.
Mesh instances must not receive real-time shadows.
There is an upper limit on the total number of mesh indices in the entire batch, which varies for the graphics API and platform used, which is around 32,000–64,000 indices (check out the documentation/previously mentioned blog post for specifics).
It is important to note the term material references because, if we happen to use two different materials with identical settings, the Rendering Pipeline is not smart enough to realize that, and they will be treated as different materials and, therefore, will be disqualified from dynamic batching. Most of the rest of these requirements have already been explained; however, a couple of these requirements are not completely intuitive or clear from their description, which merits some additional explanation.