Updated August 2020. 10 min read

スマートなゲーム開発のパイプラインを構築する

このページで学ぶ内容:ゲーム開発サイクル全体を見通せるガイドです。Unity フィールドエンジニアの Valentin Simonovによるヒントに従えば、スマートな開発パイプラインを構築できるようになり、最終的には、よりパフォーマンスの高い、優れたコンテンツをリリースすることができるようになります

Unity-コラボレーションのために Unity Teams を設定する

ゲームプロジェクトの計画とリサーチ

This is the most important part of any software development project: decisions made in this phase set the course for your entire development cycle. 

Map features to target platforms

  • Check that all planned features work on all target platforms. This is especially relevant for WebGL, which has some constraints regarding memory management, multithreading, networking and plugin support.

Specify the minimally supported devices for your project 

  • Have them available to your development and QA teams.
  • Test early and throughout development to maintain a realistic performance and frame budget.

Set frame and asset budgets early on

Define budgets for:

  • Models: how many vertices is the target device able to render?
  • Assets: how detailed should models and textures be?
  • Scripts and rendering: what % of the frame do you have for logic, rendering,
    Effects and other subsystems?

Set Scene and prefab decomposition early on

  • Split levels into (additively loaded) scenes.
  • Move separate objects into Prefabs. Nested Prefabs further increase scene decomposition and reduce merge conflicts.
  • Agree on the main scene locking mechanism.

Plan your asset pipeline process 

The import process needs to accommodate artists’ specs for assets. 

  • If possible, involve a technical artist from the beginning to define this process.
  • Define clear guidelines on asset formats and specs.
  • Use Asset Postprocessors to automate asset importing.

Line up your Build and QA process 

  • Set up a build machine, or, turn on and set up Unity Teams.
  • Establish a process for:
    • Publishing features to the release build
    • Testing new builds
    • Automating tests
    • Recording statistics

Prototype ideas, but prepare to start actual project from scratch

After building a prototype and getting it approved by the management, strongly consider starting it from scratch. 

  • Decisions made during prototyping usually favor speed.
  • Basing your game on a bunch of hacks is not a good start for any project.

More tips:

Optimizing graphics performance

Modeling characters for optimized performance

Art assets best practice guide

The new asset import pipeline in Unity

Nested Prefabs

QA your code with Unity Test Framework

Leverage next-gen crash and error data with Backtrace

Unity プロファイラー

開発のスピードアップ

Follow these best practices to speed up development and boost the quality of the final product.

Set up correct version control 

  • Use text serialization (by default in Unity).
  • Set up built-in YAML merge tool. See more about SmartMerge here. 
  • Set up commit hooks. See more here

Use the Cache Server 

  • Switching platforms decreases development speed.
  • Make sure to set up the Cache Server for your team.

Avoid storing static data in JSON or XML files

  • This results in slow loading.
  • Parsing generates garbage.
  • Instead, for built-in static data use ScriptableObjects with custom editor tools.

Don’t leave unused assets, plugins and duplicated libraries in your project

Unused assets in your project can still be built into the game. Make sure that you don’t leave garbage in your project: if you set up a version control system, restoring files should be easy.

  • Check what dependencies assets from the Asset Store drag into the project. For example, you might be surprised to find that you have five different JSON libraries in the project.
  • Check for outdated assets and scripts from early prototypes.
  • Moving old assets to the “removed” folder still results in resources and scripts being built into the game.

Repetitive actions require manual work

  • For every repetitive task there should be a script automating it.
  • Make sure that you can “play” the game or interactive content from any scene.
  • Consider a solution, such as Cloud Build, that automates the build process. 
  • For larger teams, Unity Build Server licenses can be a useful option because they offload project builds to network hardware. 

Profile your project on target devices as well as in the editor 

  • Always profile the content on your target device; if you profile in the editor only, you can miss performance bottlenecks.

Use both built-in and platform-specific profiling and debugging tools

Here are resources to learn about Unity’s profiling tools:  

Profile and optimize early on

  • The longer you wait with profiling, the larger the performance costs can become. 
  • Start profiling early on, so you’re sure your project fits into the frame, memory and disk size budgets.
  • Profile before your optimize, so that you have the data you need to optimize actual bottlenecks. 

Make sure you know as much as possible about your target platform(s) 

  • Desktop, mobile and console platforms have very different bottlenecks.

More tips

Profiling, optimizing, bugfixing, and general QA processes are necessary both during development and for updating our live games. A couple of Unity solutions to consider pre- and post-launch are Backtrace and Game Simulation. 

Backtrace automates the collection and analysis of crash and exception reports. It works cross-platform. See this blog post  for a good introduction. All Unity users can try it for free for 30 days.

Game Simulation is ensures playtesting before you launch is both time and cost-efficient. It uses cloud simulation to optimize your game balance more efficiently and accurately. You can sign up for free access here.

インポート設定

正しいアセット設定の選択

Assets take up most of the size of your game. Save time on optimizing by thinking carefully about Asset settings.  

Set up Sprite Atlases correctly

  • Make sure that you use Sprite Atlases for sprites used together in a scene. This will reduce the number of draw calls in the game/interactive content.
  • Or, consider using Tilemap, which can improve performance of 2D games. Get some tips for optimizing with Tilemaps here

Set up texture settings correctly

  • Make sure that you know the right texture settings for the target platform:

    • What compression does the platform support?
    • Do the textures need mip maps?
  • Set up an automated way to apply these settings for new textures using AssetPostprocessor API as shown by this project.
  • Prevent artists from committing textures with wrong settings.

Try the Addressable Asset System 

The new Addressable Asset System provides a framework to solve a set of common problems related to addressing, building, and loading assets. It handles asset management overhead by simplifying content pack creation and deployment. Try these resources for more information:

Simplify your content management with Addressables

Addressable Asset System docs

Addressables for live content management

プログラミングの生産性向上

コードアーキテクチャに関するベストプラクティスに従って、生産性を高めましょう。

コードエディターの効率的な使用方法を理解する 

  • コードエディターのすべての機能とショートカットを理解しておく。これにより、日常的なタスクをスピードアップできます。 
  • Visual Studio を使用する場合は、こちらのビデオで Unity プロジェクトの作業時のヒントとコツを確認する。または、こちらのビデオで JetBrains Rider に関するヒントを確認してください。 

抽象化したコードは避ける 

  • 抽象化された大規模なコードは実行速度が遅く、IL2CPP がより多くのコードを生み出す必要があるため、ほとんどの状況で適さない。 

明確なアーキテクチャの規約を作成し、文書化する

  • コードを記述するときは、同じタスクを実行するために異なるメソッドを使用しない。例: 

    • 設定のフォーマット (ファイル、プロパティ、アセット)。
    • イベント(Unity イベント、C# イベント、SendMessage)。
  • どのマネージャーがどのオブジェクトを担当するかを定義する。

Unity フレームループを理解する

  • Awake、OnEnable、Update、その他メソッドが呼び出されたとき。
  • コルーチンが更新されたとき。
  • FixedUpdate が実行された方法。

 

スクリプト初期化のロジックを Unity の実行順に依存させないようにする 

  • ゲーム中に MonoBehaviour がインスタンス化されると、Unity はその Awake メソッドと Start メソッドを呼び出します。ゲームが単純なうちは、最初のシーンがロードされたときに各 MonoBehaviour がインスタンス化される順序は問題にならないかもしれません。ただ、後になって「Project Settings」の「Script Execution Order」リストを使用してこの順序を変更したくなることはあるでしょう。しかし、このリストに含まれるスクリプトが増えると、このリストへの依存が原因で、追跡が困難なバグが発生する可能性があります。その場合は、起動時に他のすべての MonoBehaviour に対する初期化関数を呼び出すスクリプトを作成することをお勧めします。

ロジックやアニメーションのスクリプトを作成する際にフレームレートを把握しておく

  • FPS に依存しないスクリプトには Time.deltaTime を使用する。

追加のヒント:

ScriptableObject を使って構築するための 3 つの方法

より優れたスクリプティング体験を

 

Unity-CPU プロファイラー

CPU パフォーマンスの最適化

CPU 使用率を最適化して、スムーズなパフォーマンスを実現し、バッテリ寿命を延ばしましょう。  

Update() メソッドの使用を控える

  • ネイティブ -> マネージドコールには、ある程度のオーバーヘッドがある。代わりにカスタムマネージャーを使用してください
  • カスタム挙動を Update/Awake/Start メソッドが定義された抽象クラスから継承しないようにする。

ゲーム内のさまざまなシステムの更新頻度を定義する

すべてのシステムをフレームごとに更新する必要があるわけではありません。以下の領域を確認します。

  • 移動するオブジェクト
  • AI と経路検索
  • ゲームの状態のロギングと保存
  • その他、「重くなる」システム

以下のような、頻繁に必要になるデータをキャッシュする

  • リフレクション
  • Find()
  • Camera.main
  • GetComponent()

頻繁にインスタンス化されるオブジェクトをプールする

  • オブジェクトのインスタンス化には時間がかかる。
  • ゲーム/コンテンツの起動時にオブジェクトのプールを作成する。
  • 新しく作成する代わりにオブジェクトを再利用する。

フレームごとにメモリを割り当てない

  • フレームごとに小さい割り当てを行うと GC スパイクの原因になる。
  • すべての割り当ての排除を試行する。

次のようなメモリ割り当て API の代替手段を試す。 

  • LINQ。
  • 文字列の連結。
  • 次の配列を返す Unity API: 
    • Physics.RaycastAll、Mesh.vertices、GetComponents など。

追加のヒント:

1K 更新呼び出し

Unity の進化したベストプラクティス

 

Unity の GPU プロファイラー

GPU パフォーマンスの最適化

ここで紹介するヒントに従って、グラフィックパフォーマンスのスパイクを回避しましょう。

モバイルゲーム内のオーバードローはパフォーマンスのボトルネックの原因となるので避ける

  • モバイル GPU は、毎秒限られた数のピクセルのみ描画できる。
  • 必要ない透明な画像を描画しない。
  • より複雑なメッシュを使用して完全に透明な領域を切り抜く。

モバイルプロジェクト内のシェーダーにはユニバーサルレンダーパイプラインを使用する

ダイナミックバッチングを中断する可能性があるような設定ミスに注意する

  • オブジェクトが動的にバッチ処理されるには「類似」している必要がある。
  • フレームデバッガーに、特定のオブジェクトがバッチ処理されなかった理由が表示される。
  • ユニバーサルレンダーパイプラインで SRP Batcher を使用すると、バッチ処理されるオブジェクトの数を増やすことができる。 

LOD を正しく設定する

  • LOD により、カメラから遠いオブジェクトのレンダリングを効率化できる。 

追加のヒント

ドローコールがバッチ処理されない理由

モバイル最適化に関するベストプラクティス

Unity-Unity UI

UI のパフォーマンスを最適化する

Unity UI はアーティストにとって使いやすいツールです。ここで紹介するヒントに従って、UI のパフォーマンスを維持しましょう。

さまざまな解像度とアスペクト比を考慮する

  • デバイスでさまざまな解像度とアスペクト比で UI をテストする
  • デバイスによって異なる UI 画面を作成する方がよい場合がある

アニメーション化された要素を別のキャンバスに移動する 

  • 要素が変更されるとキャンバスは新しく結合されたメッシュを作成するため、複雑なキャンバスではコストがかかる可能性がある。 

新しい UI ウィンドウが開くときにラグが発生しないようにする

  • 新しいウィンドウや UI の大きなチャンクが作成されると、ゲームにラグが発生する。以下を行うことにより、この影響を最小化します。 
  • UI ウィンドウをより単純にする。
  • UI を複数のパーツに分割する。
  • ウィンドウをキャッシュする。

リストに大量のアイテムが含まれないようにする

  • 一度にすべてを作成する代わりに、リスト項目を動的に再利用する。
  • リスト内にネストされたキャンバスを作成する。

こちらのようなオープンソースの実装を使用してください。

追加のヒント

Unity で目を引くような UI をデザインする

弊社のウェブサイトは最善のユーザー体験をお届けするためにクッキーを使用しています。詳細については、クッキーポリシーのページをご覧ください。

OK