Skip to main content

Dynamic Batching

Dynamic Batching is an optimization technique used in rendering engines to reduce overhead on the draw calls issuing process by merging several draw calls into single one.

Dynamic Batching aims to improve performance on older and less powerful devices. However, with modern consumer hardware, the CPU workload associated with dynamic batching can exceed the benefits of minimizing draw calls, ultimately leading to a decrease in performance.

Draw Call Conditions

A single draw call is batchable if the following conditions are met:

  • The Dynamic Batching option is enabled in the Playworks Plugin Window.
  • The Mesh used by the draw call is indexed (uses Index Buffer).
  • The draw call is not rendered using instanced rendering (e.g. particle systems are not batchable).

Skinned meshes are not batchable.

Two draw calls could be batched if the following conditions are met:

  • The Material instance used by both draw calls is the same.
  • The shader keywords used by both draw calls are the same.
    • Both draw calls should use the same shader features (e.g. lightmaps, shadows).
  • Mesh parameters/Uniforms used in rendering are the same for both draw calls.
  • Sort keys are the same.
    • The rendering order of the draw call could be changed without an effect on the rendered frame.
  • The layout of the Vertex Buffer should be the same for both draw calls.
    • Both meshes should have similar data (e.g. Position, Texture Coordinates, Color).

Dynamic Batching cannot be applied to GameObjects that have mirroring within their Transform component.

For example, if two GameObjects have different scales, with one having a scale of 1 and the other having a scale of -1, they cannot be batched together. See Unity Documentation for more details.

How does Dynamic Batching work with Playworks Plugin ?

Playable tries to lower pressure on both CPU and GPU by not calculating batches every frame, instead it caches previously allocated batches, and recalculates them only when there is a breaking change that makes some of the batch data incorrect.

This could occur if any of the following conditions are met:

  • The hierarchy of the scene has changed
    • The affected batches will be recalculated.
  • The vertex buffer of one or more of the instances has changed (typically happens during animations).
  • The mesh parameters have changed.

However, Playable will not recalculate batches if there was any other changes. A position change, for example, reuses previously allocated batches.

Although data buffers that contain vertices and indices will remain unchanged, modifications to the transform (position, rotation, or scale) will result in changes to the Model matrix, which are then applied and updated. This approach saves rendering time while maintaining the visual integrity of the image.



Supported Features

UIYesSupports all types of Canvas UI (Overlay, Camera, World), and all built-in UI elements (Image, Text, Toggle, etc.)
3DYesExcept: Particle Systems and Skinned Meshes
Built-in Rendering Pipeline (BIRP)Yes
Universal Rendering Pipeline (URP)NoDynamic Batching works only in BIRP at the moment
High Definition Rendering Pipeline (HDRP)NoDynamic Batching works only in BIRP at the moment

Unity versions support

Dynamic Batching works on all versions of Unity that Playable can run.

Limitations and Performance Characteristics

Dynamic Batching could increase performance in some scenes, especially if the scene contains many similar objects that are close to each other in the hierarchy. For other scenes, if there are many/all different objects or similar objects scattered across the hierarchy, it does not impact performance or make it inefficient for some devices. Please, measure performance on the target devices to see the performance changes for the scene while using Dynamic Batching.

If there is a breaking change in the batch (see the previous section for details) the Playworks Plugin will regenerate this batch by allocating new GPU buffers and merging meshes together. In cases where breaking changes occur frequently for many batches, performance can be worse than if Dynamic Batching wasn't used.

The amount of draw calls that could be batched together and the time to make a batch depends on device capabilities. On some low-end devices if scene contains many complex objects (complex meshes or shaders), Dynamic Batching could perform worse than regular rendering without Dynamic Batching.

Recommendations for using Dynamic Batching

  • Use the same material for multiple objects.
  • Keep similar objects close in the hierarchy.
  • Animated objects should be separated from non-animated objects in the hierarchy.
  • Try to group objects in the hierarchy the same way as described in the above.
    • See conditions for when two draw calls could be batched.
  • Measure the playable performance on the target device.

If Dynamic Batching is negatively impacting performance or resulting in distortions in the final image, it is recommended to turn it off.

Please report any issues with Dynamic Batching to our support team via Unity Playworks Intercom.

User Guide

  1. Open a project of your choice.
  2. Import the Playworks Plugin plugin.
  3. Create or open existing scene.
  4. Add batchable objects to your scene.
    1. see our supported features for Dynamic Batching to check what objects are batchable.
  5. Open the Playworks Plugin Window and enable Dynamic Batching:
    1. Check Settings → Advanced → Dynamic Batching optionimages-medium
  6. Export the project and test the results:
    1. You can make sure batching is working by taking a look at the frame debugger (See the spector argument documentation). In the captured frame you could see that some of the draw calls are rendering several objects (use scene with disabled Dynamic Batching for comparison).
    2. You can also toggle Dynamic Batching in runtime, and measure performance, for that you could use built-in fps counter. See FPS Counter.