Dynamic batching is at the top of my That’s Neat-O! list, but it just doesn’t seem to be working as advertised (at least in my app).
When I drag two copies of a prefab to the scene (so there should be no variations in material / scale or anything else that would invalidate dynamic batching), the maximum vertex count per object I can get away with is about 115. E.g., I drag a plant prefab (at 120 vertices / 309 tris, one shader pass) to a blank scene twice, and I get two estimated draw calls, no batched draw calls.
I’m counting vertices based on the “Verts” field in the rendering statistics window.
I can’t think of any reason why this would be… maybe someone has an idea?
I tried creating a new project with one of the assets, but the problem still persists. Maybe I’m totally out of my gourd am I’m just missing something incredibly obvious… in any event, I uploaded the zipped project. I get no batching according to the rendering statistics window in the test scene…
not around my mac but one last idea: you are looking at the stats in game mode, right? Not while it is not running and you are in edit mode, cause the batching is a runtime thing. (I know a stupid question but to be sure is better than “i think” )
the prefabs aren’t skinned, right? cause they won’t batch
In my main project they’re definitely using the same material… I’ve printed out the instance IDs of the materials and they all match. It should be the same for my test project - after all, I’m just instantiating prefabs, and unless my understanding is incorrect, instantiated prefabs share the same material until modified.
Also, they’re not skinned. Actually in the test project I uploaded, they have animation components attached (accidentally imported with animation, though they have no animation and thus generate a mesh filter, not a skinned mesh filter), but even after re-importing without them the problem is still there.
That makes no difference. Unity has no knowledge of what scale you are using, so there is no “close”. If objects share the same material, they are batched.
The only other factor is the number of polygons. The manual uses the wrong word–it seems to be 300 triangles, not 300 vertices.
It is not a runtime thing. Only static batching is runtime; dynamic batching is automatic.
Drawcalls will vary depending on where my camera is, even if all of my objects share the exact same material (and are indeed less than 300 vertices). And they are static, and I got Advanced.
Unity seems to fail at batching some objects, that’s pretty obvious.
The more I have objects, the more batching will fail.
(15 objects scene = 4 DC, 100 objects = 60 DC, etc)
What is strange is that the overall FPS didn’t seem to be impacted by this high number.
Well, yes…only objects in the view frustum generate draw calls.
Static batching has no polygon limit.
Only dynamically batched objects have the 300 polygon limit; static batching is different.
I’m pretty sure there’s no bug. I haven’t seen any evidence of batching failing to work as described (aside from the vertex/polygon mixup in the docs).
It was to point out that static objects even fulfilled the dynamic requirements, so they should really have no reason not to be batched
Also, if only objects in the view frustrum are batched, and out-of-view ones are culled, I should really have a single drawcall for every camera position.
Are you changing materials at runtime, maybe? Altering a material in any way (changing offset/tiling, alpha values, anything) creates a new material at runtime, so this can’t be batched anymore.
Most of my assets are sub-300 tris and still not batching (like in the batch-test project that I attached to this thread, which has a single asset with 135 verts / 180 tris).
As for materials, I don’t know how I could possibly be changing the material in the attached project. All I did was create a prefab and instantiated it twice. That’s it.
Yep, remove another 37 tris and it will batch. Actually the wording in the docs is a pretty confusing “bug” and should be fixed…if someone else hasn’t reported it, I will.