Unity 2020.1 ベータ版で更新された BuildReport API は、プロジェクトのビルド時間に関する情報をより詳細に、アセットレベルまで分析して提供します。この情報はイテレーション時間の最適化に役立ちます。
Unity マニュアルの BuildOptions.DetailedBuildReport に関するページでこの新しい API の使用方法をご確認の上、Build Report Inspector をプロジェクトに追加すれば、新しいビルドレポートを簡単に調査していただけるようになります。
大量のコンテンツを含むプロジェクトのビルド時間は非常に長くなる場合があります。結果として、特に複数のプラットフォームでテストを行う場合には、イテレーションに掛かる時間も伸長します。
Unity 2018.1 では、Unity のビルドプロセスに関する情報を提供する BuildReport API が公開されました。以来、BuildPipeline.BuildPlayer によって戻された BuildReport オブジェクトには、ビルドプロセス中に実行されているステップに関する情報や、どのアセットがビルドサイズに寄与しているか、またどのエンジンモジュールがビルドに含まれているかの情報が含まれるようになっています。
Unity 2020.1 では、新しい BuildOptions.DetailedBuildReport オプションを API 関数 BuildPipeline.BuildPlayer に渡せば、BuildReport オブジェクト内でより多くの情報(より詳細なビルドステップ、どのシーンがビルド内のアセットを使用しているかの概要など)が入手可能になります。
Build Report Inspector パッケージ
BuildReport API は、プロジェクトのビルド時間を分析するカスタムツールの記述を可能にします。
この使用方法を学ぶひとつの方法は、Unity の提供する Build Report Inspector を参照することです。
Build Report Inspector は、Unity のパッケージマネージャーウィンドウから追加できます。Advanced メニュー内にある Show Preview Packages にチェックマークを入れて、リスト内で Build Report Inspector を選択し、「Install」ボタンをクリックしてください。
こちらの GitHub レポジトリから、Build Report Inspector スクリプト(将来的な実験版も含む)もご入手いただけるほか、改良に関するご意見もお寄せいただけます。
Build Report Inspector は、コマンドメニュー Open Last Build Report を Window メニューに追加します。コマンドメニュー Open Last Build Report をクリックすると、最も最近のビルド中にプロジェクトから検知可能な場所に生成されたビルドレポートファイルがコピーされ、それが選択されます。これによってそのコンテンツがインスペクター内で以下のように表示されるようになります。
BuildReport.steps 内の追加的な詳細
BuildOptions.DetailedBuildReport オプションを使用してビルドすると、新しいビルドステップが BuildReport.steps 内にリストアップされます。
1 ミリ秒よりも短いビルドステップは(ノイズを多く発生させるため)リストに含められません。
新しくレポートされるステップには以下が含まれます。
- ビルドのアセットの読み込み時間と書き込み時間
- ビルド中のガベージコレクション時間
- アセットの依存関係の処理時間
- カスタムのアセットバンドルのビルドの詳細と時間
Unity マニュアルの BuildOptions.DetailedBuildReport のページに、このオプションの使用方法を示すエディタースクリプトの例が掲載されています。
この例を以下のように修正し、BuildOptions.DetailedBuildReport フラグを使用して BoatAttack プロジェクトをビルドすることができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
using UnityEditor; using UnityEngine; public class DetailedBuildReportExample : MonoBehaviour { [MenuItem("Build/DetailedBuildReport example")] public static void MyBuild() { BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); buildPlayerOptions.scenes = new[] { "Assets/scenes/MainMenu.unity", "Assets/scenes/_levels/level_Island.unity" }; buildPlayerOptions.locationPathName = "DetailedReportBuild/MyGame.exe"; buildPlayerOptions.target = BuildTarget.StandaloneWindows64; buildPlayerOptions.options = BuildOptions.DetailedBuildReport; var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions); } } |
上記のスクリプトを Boat Attack プロジェクトの Assets/Editor フォルダーに追加し、エディターのメニューで Build/DetailedBuildReport サンプルをクリックすると、プロジェクトのビルドが開始されます。ビルドの終了時に、ビルドレポートに追加的なデータが含められます。
ここで前項の説明通りに Window/Open Last Build Report コマンドを使用すると、以下のように、追加的なステップがレポートに含められていることが確認できます。
この追加的な情報によって、プロジェクトのビルドに当たって時間の掛かるステップとアセットを特定することが可能となります。
時間の掛かるアセットが特定できたら、それらをより軽量な「開発」版に差し替えることで、イテレーション時間を短縮することができます。
特定のアセットを使用している全てのシーンを見付ける
重いアセットを差し替えるプロセスでは、特定のアセットがビルド中のどのシーンに含まれるのかを正確に把握することが往々にして役立ちます。
ビルド中に BuildOptions.DetailedBuildReport オプションが使用された場合、この情報は BuildReport 内でメンバー BuildReport.scenesUsingAssets として使用可能になります。
プロジェクトに Build Report Inspector を追加した場合は、ScenesUsingAssets タブからこの情報を確認できます。
開発中には、こうしたアセットをより小さなものに差し替えたり、それらを参照しているシーンなしでビルドプロファイルを作成すると、イテレーション時間の短縮に繋がります。
Unity 2020.1 ベータ版とウェビナー
Detailed Build Report を使用して、プロジェクトのビルド時間に寄与している要素を特定し、その情報を使用してイテレーションループを最適化しましょう。Unity 2020.1 ベータ版 で本機能をご試用の上、ぜひご意見をお聞かせください。4 月 20 日米国太平洋標準時 午前 9 時(日本時間 21 日 午前 2 時)から、Unity 2020.1 ベータ版に関するウェビナーを開催し、新機能のご案内と更新情報をお届けします。ウェビナーへの参加登録はこちらから行っていただけます。本機能あるいはバージョン 2020.1 の他の機能に関してご不明な点がある方のために、2020.1 ベータ版についてのウェビナー後に Q&A セッションも行います。フォーラムからご質問をご投稿ください。(※ウェビナーは終了しましたが、オンデマンドでご視聴いただけます。)
関連する投稿
Comments are closed.
9 replies on “ビルド時間を詳細に把握しよう”
Could you improve build time for HDRP/URP prjects? Moreover, could you reduce size of projects?
Hi Valarus, the screenshots in this blog post are taken from project https://github.com/Verasl/BoatAttack , which is using the Universal Render Pipeline.
You can definitely get Detailed Build Times for projects using Scriptable Render Pipelines.
A cause of long build times that I have seen several times is a high number of shader variants in the project.
You can use Shader Variants Stripping to reduce that number and improve your build times (and size). You can find more information about Shader Stripping from the following links:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@9.0/manual/shader-stripping.html
https://blogs.unity3d.com/2018/05/14/stripping-scriptable-shader-variants/
Is there any reason not to use the DetailedBuildReport option? Just wondering why that’s an option. The detailed report is much appreciated, thank you!
Thanks for your comment Peter.
If your build contains a lot of assets, the BuildOptions.DetailedBuildReport option can make the Build Report file much bigger.
The first time you inspect your project’s Build Report, you might prefer to start with a simpler overall view.
We made this feature an option, so that you can still start from the simpler view ; and later decide to dive into more details when you need.
Does the detailed report affect the build time? I know it sounds counterproductive, I’m curious about how is differs from normal reporting: Is there more info being pulled, or more analytics running, or just more already existing data being dumped into the report?
Hi Joaquin, the build steps executed by Unity during a call to BuildPlayer are the same when BuildOptions.DetailedBuildReport is disabled or enabled.
For each significant build step, we store a message into an internal list. We include that list to the final Build Report at the end of the build.
When you keep BuildOptions.DetailedBuildReport disabled, many of those steps will be executed silently, and no message about them will get into the list.
If you enable BuildOptions.DetailedBuildReport, we will include more new messages in the list. We will therefore copy more messages (strings) during the build process. We also execute a final loop to resolve the names of objects appearing in the messages.
When I checked on project https://assetstore.unity.com/packages/templates/tutorials/3d-game-kit-115747 for example, build time was 3% longer with BuildOptions.DetailedBuildReport enabled.
Thanks for your great answer!
So does this support addressables yet? Right now there is 0 info about addressables build times or build sizes.
Hi Mike, a future version of the Addressables package (maybe 1.8) will output two new report files containing timings and notes about a build.
At first the format of these new files will slightly differ from the format of the player BuildReport, but we are thinking about integrating them together.
With current Addressables package (1.7.5), you can inspect the size of the files on your disk: you can obtain their paths from the FileRegistry class.