Batch meshes at runtime
Batch static objects with the StaticBatchingUtility API, or dynamic GameObjects with dynamic batching.
Read time 2 minutesLast updated 23 days ago
For more information about batching, refer to Introduction to batching meshes.
Batch static GameObjects at runtime
To batch static GameObjects at runtime, for example GameObjects you create procedurally, follow these steps:
-
Select each mesh you want to batch, then in thewindow enable Read/Write enabled.Inspector
?
-
Use the StaticBatchingUtility API to batch the meshes. The StaticBatchingUtility.Combine method combines GameObjects and prepares them for static batching.
You don't need to enable the static batching setting in the URP asset, HDRP asset, or .
Player Settings
?
If a mesh is culled because it's outside the camera view, Unity might split the batch into two batches, to avoid a gap in the combined vertex buffers.
You can only change the position, rotation, and scale of the whole batch at runtime, not the individual meshes.
Batch moving GameObjects at runtime
To batch moving GameObjects, enable dynamic batching.
Follow these steps in the Built-In Render Pipeline:
- Go to Edit > > Player.Project Settings
?
- In the Other Settings section, enable .Dynamic Batching
?
Dynamic batching transforms all geometry into world space. To disable dynamic batching in a custom shader so you can access object space, enable Disable batching in the Shader Import Settings window of the shader.
You can also disable batching by setting the tag to in the subshader block of a shader. For example:
DisableBatchingTrueSubShader { Tags { "DisableBatching" = "True" } ... }