I have 6 different sprites in my scene that are a part of a same atlas,
all of them are using Sprites-Default material, Default sorting layer and 0 order in layer.
They differ in their position and sprite used only.
Instead of getting 1 draw call as one would expect, I get 4.
On consulting the profiler, I see that 3 of the sprites are batched in a single draw call and 3 cause one draw call each.
If I disable those 3 sprites that do not batch successfully and put in the same positions instances of sprites that did batch successfully, I indeed get 1 draw call.
If I disable sprites that did batch successfully and duplicate them one more time to a total of 6, bring them forward a bit, I get 0 draw calls saved by batching.
If I reorder the sprites that failed batching so that SAME sprites are next to each other in the Z. I get 3 draw calls with 2 saved by batching. And further inspecting the profiler shows that there are two batched draw calls and one single sprite draw call.
Number of vertices shouldn’t be a problem, there are about 210 vertices in total.
Sprite batching seems totally unpredictable!
In earlier tests, I had 2 identical scenes, the only difference being one used sprite renderers and other used mesh renderers.
Everything else was totally the same, position and sprites, everything. The sprite renderer and mesh renderer settings were all left at default.
The one using mesh renderers had 8 draw calls, the one using sprites had 192. 192! That is 24x more!
Strangely, the FPS was not all that different (1 or 2 frames less in the sprite version), but that could be attributed to me having good PC specs. The performance would have been much different if I was testing it on a mobile phone.
Of course, since sprite renderers had different meshes they had different total vertex count, sprite scene having 126,3k vertices and mesh scene having 85,8k vertices in total. So naturally, one would expect sprites to have more draw calls because number of vertices per batch is limited. But one wouldn’t expect it to have 24x times more drawcalls!!
What is going on??
P.S. I am talking about dynamic batching since sprites don’t get statically batched, but if you take into account that meshes CAN get statically batched, the final performance difference is staggeringly in favor of meshes!