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.
静的バッチ処理は CPU で頂点を変換しないので、動的バッチ処理 よりも効率的です。静的バッチ処理のパフォーマンスへの影響については、パフォーマンスへの影響 を参照してください。
このセクションでは、静的バッチ処理とレンダーパイプラインの互換性についての情報を紹介します。
機能 | ビルトインレンダーパイプライン | ユニバーサルレンダーパイプライン (URP) | HD レンダーパイプライン (HDRP) | カスタムのスクリプタブルレンダーパイプライン (SRP) |
---|---|---|---|---|
静的バッチ処理 | あり | あり | あり | あり |
Unity はビルド時、ランタイム時に静的バッチ処理を行うことができます。原則として、アプリケーションをビルドする前にゲームオブジェクトがシーンに存在する場合は、エディター を使ってビルド時にゲームオブジェクトをバッチ処理します。ランタイムにゲームオブジェクトとそのメッシュを作成する場合は、ランタイム API を使用します。
ランタイム API を使用すると、静的バッチのルートのトランスフォームプロパティを変更することができます。つまり、静的バッチを構成する結合したメッシュ全体を移動、回転、または拡大縮小することができます。個々のメッシュのトランスフォームプロパティを変更することはできません。
ゲームオブジェクトのセットに対して静的バッチ処理を使用するには、ゲームオブジェクトが静的バッチ処理の対象である必要があります。共通のバッチ処理の使用情報 に記載されている基準に加え、以下を確認してください。
DisableBatching
タグが true に設定されているシェーダーを持つ マテリアルを使用しない。静的バッチ処理のパフォーマンスへの影響については、パフォーマンスへの影響 を参照してください。
エディターでビルド時に静的バッチ処理を有効にすることができます。
ビルド時に静的バッチ処理を行う場には、以下を行います。
Unity は、共通の使用情報 に記載されている条件を満たす場合、自動的に静的メッシュを同じドローコールでバッチ処理します。
ノート: ビルド時に静的バッチ処理を行うと、Unity はランタイムに CPU リソースを一切使用することなく、静的バッチ用のメッシュデータを生成します。
ランタイムに静的メッシュをバッチ処理するために、Unity はStaticBatchingUtility クラスを提供しています。静的な StaticBatchingUtility.Combine メソッドは、渡されたゲームオブジェクトを結合して、静的バッチ処理の準備をします。これは特に、ランタイムにプロシージャルに生成されたメッシュに有効です。
ビルド時の静的バッチ処理とは異なり、ランタイムのバッチ処理では、Static Batching Player 設定を有効にする必要はありません。この API の使用方法については、StaticBatchingUtility を参照してください。
静的バッチ処理を使用すると、結合されたジオメトリを保存するために追加の CPU メモリが必要になります。複数のゲームオブジェクトが同じメッシュを使用する場合、Unity は各ゲームオブジェクトのメッシュのコピーを作成し、各コピーを結合したメッシュに挿入します。つまり、同じジオメトリが複数回、結合されたメッシュに表示されます。Unity は、エディター またはランタイム API のどちらを使用してゲームオブジェクトを静的バッチ処理用に準備するかに関係なく、この処理を行います。メモリフットプリントを小さくしたい場合は、レンダリングパフォーマンスを犠牲にして、いくつかのゲームオブジェクトの静的バッチ処理を避けることが必要かもしれません。たとえば、密集した森林環境で樹木を静的とマークすると、メモリに深刻な影響を与える可能性があります。
ノート: 1 つの静的バッチに加えることができる頂点の数には制限があります。各静的バッチは最大 64000 個の頂点を含むことができます。それ以上の場合は、別のバッチを作成します。
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.