World Grouping Listeners

public sealed class StaticBatcherListener : WorldGroupingListener

A World Grouping Listener that performs runtime static batching on World Cell Asset Chunks (and children).

The batching is very rudimentary. Basically, for each World Cell, the batcher collects all Game Objects (which can be the Asset Chunk itself or a descendant of the Asset Chunk) with a MeshRenderer component, for each Asset Chunk attached to the World Cell.

It then batches together these renderers using StaticBatchingUtility.Combine, with the first Asset Chunk game object set as the parent.

Only renderers that are associated with the same World Cell are batched together. This is most useful for situations where each World Cell may contain one or more chunks with a lot of children that are batchable.

In order for batching to work, each game object to be batched must adhere to the following guidelines:

1) The GameObject is active. You should either ensure the Grouping has Auto Activation enabled or you should activate the Asset Chunks manually in a Grouping Listener set before this one in the array.
2) The GameObject has a Mesh Filter component, and that component is enabled.
3) The Mesh Filter component has a reference to a Mesh.
4) The mesh has a vertex count greater than 0.
5) The mesh has not already been combined with another Mesh (this component uses GetComponentsInChildren to gather the game objects to be batched, and checks to make sure the first child in the collected children is not already batched using its isPartOfStaticBatch property).
6) The GameObject has a Mesh Renderer component, and that component is enabled.
7) The Mesh Renderer component does not use any Material with a shader that has the DisableBatching tag set to true.
8) All game objects to be batched use the same Material.
9) Meshes you want to batch together use the same vertex attributes. For example Unity can batch meshes that use vertex position, vertex normal, and one UV with one another, but not with meshes that use vertex position, vertex normal, UV0, UV1, and vertex tangent.
10) Meshes must have read/write enabled.

Because of requirement 8, all Asset Chunks and children of those Asset Chunks on the World Grouping (associated with the same LOD Group), must use the same material. This may require you to create more World Groupings than you would normally use, and the drawbacks of that must be balanced again the performance gains of using static batching.

Properties

Name Type Description
IgnoreLODTransitions bool

Returns false.

YieldBehaviorAfterMethodExecution ListenerYieldBehaviour

Returns ListenerYieldBehaviour.YieldOrContinue.

Methods

OnAfterCellsInBatchActivated(ReadOnlyList<WorldCell>, int, int, bool, bool)

public sealed override IEnumerator<YieldInstruction> OnAfterCellsInBatchActivated(ReadOnlyList<WorldCell> cells, int batchNumber, int totalBatchesToExpect, bool cellsArePartOfLODTransition, bool immediateMode)

Called after a batch of cells are activated. The batching process occurs here, as Unity requires the game objects to be active in order for batching to work.

Parameters

Name Type Description
cells ReadOnlyList<WorldCell>

The batch of cells that were just Activated.

batchNumber int

The batch of cells that were just Activated.

totalBatchesToExpect int

The total batches of cells that will be passed to this method for the current grouping update.

cellsArePartOfLODTransition bool

Whether the batch of cells are part of an LOD transition.

immediateMode bool

Whether the method is being executed in immediate mode.

Returns

IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine. See the YieldInstruction page for more info.