I am creating a game where the player can build things by placing blocks. I do this by instantiating static prefabs at the block they click.
I am using the Built-In Renderer. The prefabs are static and are using the Standard Shader. I am having a problem with rendering tons of these prefabs at the same time. I have static batching and dynamic batching enabled. In the profiler, I see I have a low batch count and low draw call count but I am still having rendering issues.
Should I be using StaticBatchingUtility.Combine at runtime? According to the docs, you can’t add objects to the mesh it generates which is why I am not using it.
Static Batching is primarily for objects that exists when scene is loaded. Can be used for spawned objects but that comes with some non-trivial amount of CPU costs when you update it’s data (by inserting a new mesh) so is usually done on scene start or hidden in dedicated time slots (loading screens, UI switching etc). Using it as something you can call any frame introduces risk of frame drops you can do nothing about (closed engine source).
TL;DR: You can use it, but be aware of this so you can manage this cost (like delaying, placing meshes in a queue etc.).
Dynamic Batching
What you need to know about Dynamic Batching is that it comes from an era where there was no GPU Instancing yet (important detail). This is legacy solution basically. It was built to solve specific class of problems where a dozens or hundreds of quads were rendered as separate meshes - solution named “Dynamic Batching” was to merge them. It comes with significant mesh data size restrictions (read “Limitations” on it’s documentation page).
TL;DR: it was never meant to solve all batching issues and is often disabled by more senior developers as it’s “non-solution” for today standards.
So what is a better option then, you may ask.
That depends on specific details of your game.
But if most of these meshes are identical then I suggest trying GPU Instancing. If nothing else - it at least was designed to solve this specific problem and not a totally different one.