Version: 2020.3
Language : English
Static batching
Manually combining meshes

Dynamic batching

Dynamic batching is a draw call batching method that batches moving GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
to reduce draw calls. Dynamic batchingAn automatic Unity process which attempts to render multiple meshes as if they were a single mesh for optimized graphics performance. The technique transforms all of the GameObject vertices on the CPU and groups many similar vertices together. More info
See in Glossary
works differently between meshes and geometries that Unity generates dynamically at runtime, such as particle systemsA component that simulates fluid entities such as liquids, clouds and flames by generating and animating large numbers of small 2D images in the scene. More info
See in Glossary
. For information about the internal differences between meshes and dynamic geometries, see Dynamic batching for meshes and Dynamic batching for dynamically generated geometries.

Note: Dynamic batching for meshes was designed to optimize performance on old low-end devices. On modern consumer hardware, the work dynamic batching does on the CPU can be greater than the overhead of a draw call. This negatively affects performance. For more information, see Dynamic batching for meshes.

Requirements and compatibility

This section includes information about the render pipeline compatibility of dynamic batching.

Render pipeline compatibility

Feature Built-in Render Pipeline Universal Render Pipeline (URP) High Definition Render Pipeline (HDRP) Custom Scriptable Render Pipeline (SRP)
Dynamic Batching Yes Yes No Yes

Using dynamic batching

Unity always uses dynamic batching for dynamic geometry such as Particle Systems

To use dynamic batching for meshes:

  1. Go to Edit > Project Settings > Player.
  2. In Other Settings, enable Dynamic Batching.

Unity automatically batches moving meshes into the same draw call if they fulfill the criteria described in the common usage information.

Dynamic batching for meshes

Dynamic batching for meshes works by transforming all vertices into world space. on the CPU, rather than on the GPU. This means dynamic batching is only an optimization if the transformation work is less resource intensive than doing a draw call.

The resource requirements of a draw call depend on many factors, primarily the graphics API. For example, on consoles or modern APIs like Apple Metal, the draw call overhead is generally much lower, and often dynamic batching doesn’t produce a gain in performance. To determine whether it’s beneficial to use dynamic batching in your application, profile your application with and without dynamic batching.

Unity can use dynamic batching for shadows casters, even if their materials are different, as long as the material values Unity needs for the shadow pass are the same. For example, multiple crates can use materials that have different textures. Although the material assets are different, the difference is irrelevant for the shadow caster pass and Unity can batch shadows for the crate GameObjects in the shadow render step.

Limitations

In the following scenarios, Unity either can’t use dynamic batching at all or can only apply dynamic batching to a limited extent:

  • Unity can’t apply dynamic batching to meshes that contain more than 900 vertex attributes and 225 vertices. This is because dynamic batching for meshes has an overhead per vertex. For example, if your shaderA program that runs on the GPU. More info
    See in Glossary
    uses vertex position, vertex normal, and a single UV, then Unity can batch up to 225 vertices. However, if your shader uses vertex position, vertex normal, UV0, UV1, and vertex tangent, then Unity can only batch 180 vertices.
  • Unity can’t apply dynamic batching to GameObjects that contain mirroring in their Transform componentA Transform component determines the Position, Rotation, and Scale of each object in the scene. Every GameObject has a Transform. More info
    See in Glossary
    . For example, if one GameObject has a scale of 1 and another GameObject has a scale of –1, Unity can’t batch them together.
  • If GameObjects use different material instances, Unity can’t batch them together, even if they are essentially the same. The only exception to this is shadow caster renderingThe process of drawing graphics to the screen (or to a render texture). By default, the main camera in Unity renders its view to the screen. More info
    See in Glossary
    .
  • GameObjects with lightmaps have additional renderer parameters. This means that, if you want to batch lightmapped GameObjects, they must point to the same lightmapA pre-rendered texture that contains the effects of light sources on static objects in the scene. Lightmaps are overlaid on top of scene geometry to create the effect of lighting. More info
    See in Glossary
    location.
  • Unity can’t fully apply dynamic batching to GameObjects that use multi-pass shaders.
    • Almost all Unity shaders support several lights in forward renderingA rendering path that renders each object in one or more passes, depending on lights that affect the object. Lights themselves are also treated differently by Forward Rendering, depending on their settings and intensity. More info
      See in Glossary
      . To achieve this, they process an additional render pass for each light. Unity only batches the first render pass. It can’t batch the draw calls for the additional per-pixel lights.
    • The Legacy Deferred rendering path doesn’t support dynamic batching because it draws GameObjects in two render passes. The first pass is a light pre-pass and the second pass renders the GameObjects.

Dynamic batching for dynamically generated geometries

The following renderers dynamically generate geometries, such as particles and lines, that you can optimize using dynamic batching:

Dynamic batching for dynamically generated geometries works differently than it does for meshes:

  1. For each renderer, Unity builds all dynamically batchable content into one large vertex buffer.
  2. The renderer sets up the material state for the batch.
  3. Unity then binds the vertex buffer to the GPU.
  4. For each Renderer in the batch, Unity updates the offset in the vertex buffer and submits a new draw call.

This approach is similar to how Unity submits draw calls for static batchingA technique Unity uses to draw GameObjects on the screen that combines static (non-moving) GameObjects into big Meshes, and renders them in a faster way. More info
See in Glossary
.

Static batching
Manually combining meshes
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961