How to reduce draw calls using a script?

Hey all!

So I want to reduce the number of draw calls using a script. The CombineChildren.cs script doesn’t work, when attached to a parent of some gameobject it just glitches out.

Any suggestions?

Thanks!

Well, aside from combining meshes and sharing materials, or deleting objects or disabling renderers, there’s really not a lot you can do at runtime. Efficiency is something that’s best design in from the beginning, not something that’s added in at the end. Especially not arbitrarily, with no knowledge of the scene you’re trying to optimise.

Hey, angrypengiun, can u tell the detail

He means, you should condense the number of materials you use. You need to Build Atlas’ to compress the number of materials used. That’s it. That’s how you reduce draw calls.

Its probably better to do it at design time as opposed to run time. That said I had a very simple texture/mesh combiner posted here, will try to find the link.

You could also do things like remove tangents and vert colours, etc, from meshes if they aren’t being used (this helps with dynamic batching because there is a limit on the number of float values on a mesh, once exceeded a mesh will no longer batch).

Another thing you can do is to check if there are any “unbatchable” meshes between (depthwise) two “batchable” meshes with the same material as the batchable meshes. If there is you can save draw calls by creating a new material for the mesh that breaks the batch!*

  • This is because the dynamic batcher stops trying to batch a material if if finds a mesh that can’t be batched.**

** Caveat: This is behaviour from a few versions ago, its probably the same, but I haven’t tried it since 3.5.

EDIT: The link I was trying to find: http://forum.unity3d.com/threads/117155-Combine-textures-and-meshes-(reduce-draw-calls)

That’s one way, yes.

Ultimately, you need to understand what a draw call is and why they happen, and then design to use them as efficiently as possible. There’s no one single silver bullet to reduce draw calls.

I tend to experiment with CombineChildren to see how many objects i can get it working on without issues.
I tend to CombineChildren on similar objects. Try breaking your gameObjects into groups and assigning CombineChildren to the parent of each of these groups.