- Home /
Static batching not reducing draw calls but is creating batches
I'm seeing this issue in Unity 2017.4.1.
I've been working on a lot of optimisation stuff recently and currently looking at batching. I setup a scene where I'm creating objects at runtime and then adding them to a static batch using the StaticBatchingUtility with the following script:
private void Start()
{
var objList = new List<GameObject>();
//instantiate objects and populate objList
var objArr = objList.ToArray();
StaticBatchingUtility.Combine(objArr, holder.gameObject);
}
This produces the following in the memory profiler:
It looks like the static batches are being created but the draw calls aren't reducing as I would expect. If I remove the static batching code from the script and simply instantiate them and let dynamic batching be applied, the profiler displays the following:
Here, the batching is working as I would expect. I could go ahead and use dynamic batching but from what I hear static should be working better. In terms of performance, I'm not really seeing a difference between static and dynamic batching here but when I increase the number of objects in the scene, static batching tends to run a bit better. This makes me think that it might just be a big with what the profile displays rather than with the batching itself. Any helps on the issue would really be appreciated.
Spent some more looking at this and while I've not found a solution, I've narrowed it down a little. The issues seems to be occurring because the meshes being batched have submeshes. I tested the same scenario as above with a simpler mesh without submeshes and it worked fine.
Also confirmed that I'm still seeing the issue in Unity 2019.3.0a6.
In case anybody comes across this post while dealing with the same issue, I'll update what I ended up doing. Ended up just using GPU instancing on the materials ins$$anonymous$$d which isn't ideal but definitely hit a wall with progress so it saved me the headache of digging any deeper.
I did find a script that splits submeshes into separate mesh renderers but it didn't really work as I'd have liked it too. It dropped the draw calls but the actual frame rate dropped as well. When I tested this, dynamic batching and Instancing without splitting the renderers up was better than static batching with the split submeshes.
Your answer
Follow this Question
Related Questions
The combined mesh is different between static-batched objects? 0 Answers
Batching problem: Poor forest tiles don't batch [fixed but not sure why xD] 1 Answer
What is the alternative to Material Property Blocks when using SRP Batcher? 0 Answers
Why does the frame debugger say node uses different shader when it isn't? 0 Answers
When Static Batching and building, objects checked Static do not appear 1 Answer