(:3[kanのメモ帳]

個人ゲーム開発者kan.kikuchiのメモ的技術ブログ。月木更新でUnity関連がメイン。

(:3[kanのメモ帳]


本ブログの運営者kan.kikuchiが個人で開発したゲームです!

    

Unityプロジェクトを解析し、改善点を教えてくれる ProjectAuditor【Unity】【アセット】【最適化】


このエントリーをはてなブックマークに追加


この記事でのバージョン
Unity 2021.3.4f1
ProjectAuditor 0.9.0-preview

はじめに

今回はProjectAuditorというUnityプロジェクトを解析し、改善点を教えてくれるツールの紹介です!

ちなみに無料(MITライセンス)で使えます……!

Project Auditor is an experimental static analysis tool that analyzes assets, settings, and scripts of the Unity project and produces a report containing: Code and Settings diagnostics, the last BuildReport, and assets information.

Project Auditorは、Unityプロジェクトのアセット、設定、スクリプトを解析し、以下を含むレポートを作成する実験的な静的解析ツールです。コードと設定の診断、最後のBuildReport、およびアセット情報を含むレポートを作成します。
DeepL翻訳


イメージとしては以下のような感じ。

なお、Unityの人によって作られた物ではありますが、Unity公式のサポートは今の所ないようです。

Although this project is developed by Unity employees, it is not officially supported by Unity and it is not on Unity's roadmap yet. Furthermore, Project Auditor is being used on several projects but it is an experimental tool and it is still evolving. Therefore it might not work correctly depending on the version of Unity and the content of the project.

このプロジェクトはUnityの社員によって開発されていますが、Unityによって公式にサポートされておらず、Unityのロードマップにもまだ掲載されていません。また、Project Auditorはいくつかのプロジェクトで使用されていますが、実験的なツールであり、まだ進化している最中です。そのため、Unityのバージョンやプロジェクトの内容によっては、正しく動作しない可能性があります。
DeepL翻訳

GitHub - Unity-Technologies/ProjectAuditor: Project Auditor is an experimental static analysis tool for Unity Projects.


導入

導入はお馴染みのPackage Managerを使って行います。

上部メニューのWindow/Package Managerからウィンドウを開き、


左上のプラスボタンから「Add package from git URL…」を選択、


https://github.com/Unity-Technologies/ProjectAuditor.git

と入力した後にAddを押すだけで、


導入完了です。



使い方

次に使い方ですが、上部メニューのWindow/Analysis/Project Auditorからウィンドウを開き、


Analyzeを押すことでプロジェクトの解析が行われます。


なおModulesで解析する対象の項目、Platformで解析するプラットフォームを指定出来ます。


プロジェクトの解析が完了すると、解析結果が項目ごとに表示されます。

例えばCodeを選択するとボックス化等のプログラムで問題がありそうな箇所が表示されます。

さらに各項目を選択するとなぜそれが問題か(Details)、どうしたら良いか(Recommendation)

という文章も表示され、これらはコピーも出来ます。

Details
Boxing happens where a value type, such as an integer, is converted into an object of reference type. This causes an allocation on the heap, which might increase the size of the managed heap and the frequency of Garbage Collection.


Recommendation
Try to avoid Boxing when possible.

詳細
Boxingは、整数などの値型が参照型のオブジェクトに変換される場合に発生する。これにより、ヒープに割り当てが発生し、管理ヒープのサイズとガベージコレクションの頻度が増加する可能性がある。


推奨事項
可能な限りBoxingを避ける。
DeepL翻訳


他にもSettingsでプロジェクト設定の改善点を見つけられたり、

Details
The Graphics Jobs option in Player Settings is disabled.


Recommendation
Try enabling it and testing your application. This option spreads the task of building the render command buffer every frame across as many CPU cores as possible, rather than performing all the work in the render thread which is often a bottleneck. Performance will vary depending on the project.

Note: This feature is experimental on specific Unity versions and may introduce new crashes. It is recommended to test accordingly.

詳細
Player SettingsのGraphics Jobsのオプションが無効になっている。


推奨事項
これを有効にして、アプリケーションをテストしてみてください。このオプションは、ボトルネックになりがちなレンダースレッドですべての作業を行うのではなく、フレームごとにレンダーコマンドバッファを構築するタスクをできるだけ多くの CPU コアに分散させます。パフォーマンスは、プロジェクトによって異なります。

注意:この機能は特定のUnityバージョンで実験的なもので、新たなクラッシュを引き起こす可能性があります。適宜テストすることをお勧めします。
DeepL翻訳


Assembliesで各アセンブリのコンパイル時間が見れたりと、


見れたりと、様々な角度からプロジェクトを最適化するためのヒントが得られます。