playMaker

Author Topic: Static Batching  (Read 3165 times)

Sjones

  • Full Member
  • ***
  • Posts: 203
Static Batching
« on: March 12, 2013, 05:11:17 AM »
Too many draw calls? (Yes)

Making a lot of objects at runtime that are the same? (Yes)

do these objects move? (No)

Then this script is for you!

I have been testing it out in my project, made a derivative of this a few months that didn't work too well...

however I came back to it and found a working fix for it, this will combine all objects that are a child of a game object together for static batching at run time.

Quote from the unity help page on its limitations.
Quote
StaticBatchingUtility can prepare your objects to take advantage of Unity's static batching.

This step is useful as a performance optimization allowing engine to reduce number of draw-calls dramatically, but keep amount of rendered geometry intact.

By calling one of the Combine methods you will create an internal mesh which will contain combined geometry, however each original GameObject will be present in the scene and will be culled individually. The fact that GameObjects can be culled individually allows run-time to render the same amount of geometry as it would without batching, unlike combining geometry in the modeling tool. Combining geometry in the modeling tool prevents efficient culling and results in much higher amount of geometry being rendered.

Note that you do not need to call Combine methods on objects which were already marked as "Static" in the Editor. They will be prepared for static batching automatically during the Build Player step.

IMPORTANT: only objects with the same material can be batched, thus it is useful to share as many textures/material as you can.

something to also be aware of (not something I have tested but other people have said) is that your memory usage might go up, so better performance for CPU but less for memory.