Draw call batching is a draw call optimization method that combines meshes so that Unity can render them in fewer draw calls. Unity provides two built-in draw call batching methods:
Unity’s built-in draw call batching has several advantages over manually merging meshes; most notably, Unity can still cull meshes individually. However, it also has some downsides; static batching incurs memory and storage overhead, and dynamic batching incurs some CPU overhead.
This section includes information about the render pipeline compatibility of Unity’s built-in draw call batching methods.
功能 | 内置渲染管线 | 通用渲染管线 (URP) | 高清渲染管线 (HDRP) | Custom Scriptable Render Pipeline (SRP) |
---|---|---|---|---|
Static Batching | 是 | 是 | 是 | 是 |
Dynamic Batching | 是 | 是 | 否 | 是 |
The following usage information is relevant for both static and dynamic batching. For information specific to each draw call batching method, such as how to enable and use each method, see Static batching and Dynamic batching.
Mesh Renderers, Trail Renderers, Line Renderers, Particle Systems, and Sprite Renderers are supported for draw call batching. Other types of rendering components, including Skinned Mesh Renderers Cloth, are not supported. Unity only batches Renderers with other Renderers of the same type; for example, Mesh Renderers with Mesh Renderers.
Unity batches draw calls of GameObjects that use the same material. This means to get the best results from draw call batching, share materials among as many GameObjects as possible. If you have two material assets that are identical apart from their textures, you can combine the textures into a single, larger texture. This process is called texture atlasing. For more information, see the Wikipedia article on texture atlasing. When textures are in the same atlas, you can use a single material asset instead.
In the Built-in Render Pipeline, you can use a MaterialPropertyBlock to change material properties without breaking draw call batching. The CPU still needs to make some render-state changes, but using a MaterialPropertyBlock
is faster than using multiple materials. If your project uses a Scriptable Render Pipeline, don’t use a MaterialPropertyBlock
because they remove SRP Batcher compatibility for the material.
Transparent shaders often require Unity to render meshes in back-to-front order. To batch transparent meshes, Unity first orders them from back to front and then tries to batch them. Since Unity must render the meshes back-to-front, it often can’t batch as many transparent meshes as opaque meshes.
Unity can’t apply dynamic batching to GameObjects that contain mirroring in their Transform component. 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 you are not able to use draw call batching, manually combining meshes that are close to each other can be a good alternative. For more information on combining meshes, see Combining meshes.
Warning: When you access shared material properties from a C# script, make sure to use Renderer.sharedMaterial and not Renderer.material. Renderer.material
creates a copy of the material and assigns the copy back to the Renderer. This stops Unity from batching the draw calls for that Renderer.
2017–10–26 页面已修订
在 2017.2 版中添加了有关动态批处理与图形作业不兼容的备注
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.