Give Page Feedback | API

World Grouping Listeners - Static Batcher Listener

This Listener performs Runtime Static Batching on World Cell Asset Chunks. The logic to determine what to batch is very rudimentary, however, so you may wish to create a more advanced static batcher if your game requires it.

Creating A Static Batcher Listener Component

You can add this component by selecting a game object and then selecting from the Top Menu Bar:

Component -> Deep Space Labs -> -> SAM -> World Grouping Listeners -> Static Batcher Listener

Adding A Static Batcher Listener Component From The Top Menu Bar GIF

or by selecting a game object and using the Add Component menu via its inspector:

Component -> Deep Space Labs -> -> SAM -> World Grouping Listeners -> Static Batcher Listener

Adding A Static Batcher Listener Component From Add Component Menu GIF

How It Works

Basically, for each World Cell that is loaded and activated, the batcher searches through every Asset Chunk on the Cell and collects all Game Objects with a MeshRenderer component (on children of the Asset Chunk, grandchildren, etc. as well). It then batches together these renderers. Only renderers that are associated with the same World Cell are batched together. If these renderers are making use of the same Material, a single batch will likely be created (although shadows and other things may effect this), otherwise a separate batch will likely be created for each unique Material. This is most useful for situations where each World Cell may contain one or more chunks with a lot of children that are batchable.

The first Asset Chunk in the World Cell's Asset Chunk Set is made the batching parent. This allows the batches to be moved correctly when performing Origin Shifts!

Why Use Static Batching?

Static Batching can reduce the number of draw calls each frame, especially when you have many unique meshes using the same material. Do note, however, that the method that performs the runtime batching has CPU overhead; therefore, you should test your game with this Listener both enabled and disabled to determine whether it is worth using it.

Using With Multiple World Groupings

This Listener can be used with as many World Grouping (across different Worlds) as you wish; there is no need to ever create more than one Static Batch Listener component for a single scene!

When Is Batching Performed?

This Listener operates on a batch of Cells that have just been activated. Performing the static batching after the cells are activated is necessary as the StaticBatchingUtility.Combine method requires all renderers to be on active game objects.

Read/Write Enabled Meshes

Runtime Static Batching (of any kind) requires that your meshes have read/write enabled!!