Version: 2022.3
Language : English
Draw call batching
Dynamic batching

Static batching

Static batching is a draw call batching method that combines meshes that don’t move to reduce draw calls. It transforms the combined meshes into world space and builds one shared vertex and index buffer for them. Then Unity performs a single draw call that uses this combined mesh to draw all objects in the batch at once. 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
can significantly reduce the number of draw calls.

Static batching is more efficient than 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
because static batching doesn’t transform vertices on the CPU. For more information about the performance implications for static batching, see Performance implications.

Requirements and compatibility

This section includes information about the render pipelineA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. More info
See in Glossary
compatibility of static batching.

Render pipeline compatibility

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

Using static batching

Unity can perform static batching at build time and at runtime. As a general rule, if the 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
exist in a sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
before you build your application, use the Editor to batch your GameObjects at build time. If you create the GameObjects and their meshes at runtime, use the runtime API.

When you use the runtime API, you can change the transform properties of the root of a static batch. This means that you can move, rotate, or scale the entire combination of meshes that make up a static batch. You can’t change the transform properties of the individual meshes.

To use static batching for a set of GameObjects, the GameObjects must be eligible for static batching. In addition to the criteria described in the common usage information, make sure that:

  • The GameObject is active.
  • The GameObject has a Mesh FilterA mesh component that takes a mesh from your assets and passes it to the Mesh Renderer for rendering on the screen. More info
    See in Glossary
    component, and that component is enabled.
  • The Mesh Filter component has a reference to a MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
    See in Glossary
    .
  • The mesh has a vertex count greater than 0.
  • The mesh has not already been combined with another Mesh.
  • The GameObject has a Mesh RendererA mesh component that takes the geometry from the Mesh Filter and renders it at the position defined by the object’s Transform component. More info
    See in Glossary
    component, and that component is enabled.
  • The Mesh Renderer component does not use any Material with a shaderA program that runs on the GPU. More info
    See in Glossary
    that has the DisableBatching tag set to true.
  • 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.

Note: To use runtime static batching you must also set the mesh to have read/write enabled.

For information about the performance implications for static batching, see Performance implications.

Static batching at build time

You can enable static batching at build time in the Editor.

To perform static batching at build time:

  1. Go to Edit > Project Settings > Player.
  2. In Other Settings, enable Static Batching.
  3. In the Scene view or Hierarchy, select the GameObject that you want to batch and view it in the Inspector.
    Tip: You can select multiple GameObjects at the same time to enable static batching for all of them.
  4. In the GameObject’s Static Editor Flags, enable Batching Static.

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

The Static Editor Flags checkbox in the Inspector for a GameObject.
The Static Editor Flags checkbox in the Inspector for a GameObject.

Note: If you perform static batching at build time, Unity doesn’t use any CPU resources at runtime to generate the mesh data for the static batch.

Static batching at runtime

To batch static meshes at runtime, Unity provides the StaticBatchingUtility class. The static StaticBatchingUtility.Combine method combines the GameObjects you pass in and prepares them for static batching. This is especially useful for meshes that you procedurally generate at runtime.

Unlike static batching at build time, batching at runtime doesn’t require you to enable the Static Batching Player Setting. For information on how to use this API, see StaticBatchingUtility.

Performance implications

Using static batching requires additional CPU memory to store the combined geometry. If multiple GameObjects use the same mesh, Unity creates a copy of the mesh for each GameObject, and inserts each copy into the combined mesh. This means that the same geometry appears in the combined mesh multiple times. Unity does this regardless of whether you use the editor or runtime API to prepare the GameObjects for static batching. If you want to keep a smaller memory footprint, you might have to sacrifice rendering performance and avoid static batching for some GameObjects. For example, marking trees as static in a dense forest environment can have a serious memory impact.

Note: There are limits to the number of vertices a static batch can include. Each static batch can include up to 64000 vertices. If there are more, Unity creates another batch.

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