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, for visible meshes, Unity performs a series of simple draw calls, with almost no state changes between each one. Static batching doesn’t reduce the number of draw calls, but instead reduces the number of render state changes between them.
Static batching is more efficient than dynamic batching because static batching doesn’t transform vertices on the CPU. For more information about the performance implications for static batching, see Performance implications.
This section includes information about the render pipeline compatibility of static batching.
功能 | 内置渲染管线 | 通用渲染管线 (URP) | 高清渲染管线 (HDRP) | Custom Scriptable Render Pipeline (SRP) |
---|---|---|---|---|
Static Batching | 是 | 是 | 是 | 是 |
Unity can perform static batching at build time and at runtime. As a general rule, if the GameObjects exist in a scene 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:
DisableBatching
tag set to true.For information about the performance implications for static batching, see Performance implications.
You can enable static batching at build time in the Editor.
To perform static batching at build time:
Unity automatically batches the specified static meshes into the same draw call if they fulfill the criteria described in the common usage information.
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.
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.
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.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.