Dynamic batching only working for <120 vertices?

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?

are they close to each other?

Yes, within a few units. Or even overlapping. It doesn’t make a difference.

then they are not using the same material (same material means same texture, same tiling etc).

only objects with the same material can be batched

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…

205728–7581–$batch_test_876.zip (1.34 MB)

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” :slight_smile: )

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.

It’s the same when running, paused, or not running. :frowning:

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.

–Eric

I had the same issue with my scenes.

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.

I submitted a bug report for that.

Well, yes…only objects in the view frustum generate draw calls. :slight_smile:

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. :slight_smile: I haven’t seen any evidence of batching failing to work as described (aside from the vertex/polygon mixup in the docs).

–Eric

Yep, I knew for the 300 and dynamic specs.

It was to point out that static objects even fulfilled the dynamic requirements, so they should really have no reason not to be batched :slight_smile:

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.

–Eric

There needs to be a mass find/replace of “300 vertices” to “300 polygons” in the forums…

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.

No change at all. A plain, constant texture loaded on import.

I just looked at it…the object is 337 triangles, not 180. Whatever your 3D app says doesn’t count; only the number in Unity matters.

–Eric

[smacks head] Right. When I was looking for vert counts earlier, I looked in the right place, but this last time I didn’t :wink:

That should be it then…

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. :wink:

–Eric

So it’s tris, not verts ? :roll:

Anyway, all of my objects are less than 100 tris.