Version: 2023.1
言語: 日本語
WebGL development
Interaction with browser scripting

WebGL の Player 設定

Use Player settings to know how Unity builds and displays your final WebGL application. For a description of the general Player settings, refer to Player settings.

To access the WebGL Player settings:

  • From the Unity main menu, go to Edit > Project Settings > Player. The Player settings window appears.
  • Select the WebGL tab to view the WebGL Player settings.
WebGL Player 設定
WebGL Player 設定

以下のセクションのプロパティが説明されています。

Note: Although the Icon panel appears on the WebGL Player settings, there are no icon settings available because WebGL games don’t use icons.

WebGL の Publishing Settings の詳細は、WebGL のビルドと実行 を参照してください。

Resolution and Presentation

Use the Resolution and Presentation section to customize the aspects of the screen’s appearance in the Resolution section.

WebGL プラットフォームの Resolution 設定
WebGL プラットフォームの Resolution 設定

Resolution

設定 機能
Default Canvas Width WebGL キャンバス要素の幅を設定します。
Default Canvas Height WebGL キャンバス要素の高さを設定します。
Run In Background これを有効にすると、キャンバスやブラウザーウィンドウがフォーカスを失ったときにもコンテンツを継続して実行できます。

WebGL Template

WebGL プロジェクトに使用するテンプレートを選択します。

  • Default ページはグレーのキャンバスにプログレスバーがあるシンプルな白いページです。
  • Minimal ページには WebGL コンテンツを実行するのに必要な定型コードのみが含まれます。
  • PWA ページには、ウェブマニフェストファイルとサービスワーカーコードを含む Progressive Web App があります。

独自のテンプレートを指定して、完成したゲームと同様の環境でゲームを実行することができます。WebGL テンプレートの使用 を参照してください。

Splash Image

Virtual Reality Splash Image 設定を使用して、XR ディスプレイのカスタムスプラッシュ画像を指定します。一般的なスプラッシュスクリーン の設定については、スプラッシュスクリーン を参照してください。

VR のスプラッシュスクリーン設定
VR のスプラッシュスクリーン設定

Other Settings (その他の設定)

このセクションでは、以下のグループに分類されたさまざまなオプションをカスタマイズできます。

Rendering

これらの設定を使用して、WebGL プラットフォーム向けにゲームをレンダリングする方法をカスタマイズします。

WebGL プラットフォームの Rendering Player 設定
WebGL プラットフォームの Rendering Player 設定
設定 機能
Color Space レンダリングに GammaLinear どちらの色空間を使用するかを選択します。
2 つの色空間の違いの説明は リニアレンダリングの概要 を参照してください。
Auto Graphics API これを無効にすると、グラフィックス API を手動で選択して並べ替えることができます。デフォルトではこのオプションは有効になっており、Unity に WebGL2.0 が含まれ、WebGL2.0 がサポートされない場合の代替として WebGL1.0 が使用されます。
Static Batching このオプションを有効にして、静的バッチ処理を行います。
Dynamic Batching これを有効にして、ダイナミックバッチング をビルドに使用します (デフォルトでは有効になっています)。
Graphics Jobs これを有効にすると、Unity がグラフィックスタスク (レンダリングのループ) を他の CPU コア上で動作するワーカースレッドにオフロードします。これを使用して、しばしばボトルネックとなるメインスレッドの Camera.Render で費やされる時間を短縮します。
ノート この機能は実験的です。プロジェクトのパフォーマンスが向上しない場合があり、クラッシュの原因になる可能性があります。
Texture compression format WebGL のテクスチャ圧縮形式を設定するには、DXTETC2、またはASTCを選択します。正しいフォーマットを選択する方法については、テクスチャ圧縮フォーマットの概要 を参照し、スクリプトからデスクトップおよびモバイルブラウザー用のビルドを作成する方法については、WebGL のテクスチャ圧縮 を参照してください。
Lightmap Encoding ライトマップのエンコードを設定するには、Low QualityNormal QualityHigh Quality のいずれかを選択します。この設定は、ライトマップのエンコードスキームと圧縮形式に影響します。
HDR Cubemap Encoding HDR キューブマップのエンコードを設定するには、Low QualityNormal QualityHigh Quality のいずれかを選択します。この設定は、HDR キューブマップのエンコードスキームと圧縮形式に影響します。
Lightmap Streaming Enabled ライトマップに Mipmap Streaming を使用するかどうかを設定します。Unity は、ライトマップを生成するときに、この設定をすべてのライトマップに適用します。
ノート: この設定を使用するには、Texture Streaming Quality 設定を有効にする必要があります。
Streaming Priority ミップマップストリーミング でライトマップの優先順位を設定します。Unity はこれらを生成すると、その設定すべてのライトマップに適用します。
正の数値が優先されます。有効な値の範囲は –128 から 127 です。
Frame Timing Stats これを有効にすると、CPU/GPUフレームタイミング統計を収集します。
Virtual Texturing Virtual Texturing を有効にするかどうかを示します。
ノート: この設定を有効にするには、Unity エディターの再起動が必要です。
Shader precision model シェーダーで使用されるサンプラーのデフォルトの精度を制御します。詳しくは、シェーダーのデータ型と精度 を参照してください。
360 Stereo Capture Unity がステレオスコピック 360 の画像とビデオをキャプチャできるかどうかを示します。有効にすると、Unity は 360 キャプチャをサポートするために追加のシェーダーバリアントをコンパイルします (現在はWindows/OSX のみ)。有効にすると、Stereo RenderCubemap 呼び出し 中に enable_360_capture キーワードが追加されます。このキーワードは Stereo RenderCubemap 関数の外では発生しないことに注意してください。詳細は Stereo 360 Image and Video Capture を参照してください。
Load/Store Action Debug Mode ビルドしたアプリケーションでレンダリングの問題を引き起こす可能性のある未定義のピクセルをハイライト表示します。ハイライトは、ゲームビュー、または、ビルド設定で Development Build を選択してビルドされたアプリケーションにのみ表示されます。LoadStoreActionDebugModeSettings を参照してください。
Editor Only ゲームビューで未定義のピクセルをハイライトしますが、ビルドしたアプリケーションではハイライトしません。

Configuration

WebGL プラットフォームの Configuration 設定
WebGL プラットフォームの Configuration 設定
プロパティ 説明
スクリプティングバックエンド 使用するスクリプティングバックエンドを選択します。スクリプトバックエンドは、Unity が Project 内の C# コードをどのようにコンパイルし、実行するかを決定します。
Mono C# コードを .NET 共通中間言語 (CIL) にコンパイルし、共通言語ランタイムを使用して CIL を実行します。詳細は Mono を参照してください。
IL2CPP Compiles C# code into CIL, converts the CIL to C++ and then compiles that C++ into native machine code, which executes directly at runtime. Refer to IL2CPP for more information.
API Compatibility Level プロジェクトで使用可能にする .NET API を選択します。この設定は、サードパーティのライブラリとの互換性に影響する可能性があります。ただし、エディター固有のコード (エディターディレクトリ内のコードや、エディター固有のアセンブリ定義内のコード) には影響しません。

ヒント: サードパーティのアセンブリに問題がある場合は、以下の API Compatibility Level セクションに提案されている方法を試してみてください。
.Net Standard 2.1 NET Standard 2.1 と互換性があります。より小さなビルドを生成し、完全なクロスプラットフォームサポートを提供します。
.Net Framework Compatible with the .NET Framework 4 (which includes everything in the .NET Standard 2.0 profile plus additional APIs). Choose this option when using libraries that access APIs not included in .NET Standard 2.0. Produces larger builds and any additional APIs available aren’t necessarily supported on all platforms. Refer to Referencing additional class library assemblies for more information.
IL2CPP Code Generation Unity が IL2CPP コード生成を管理する方法を定義します。このオプションは、IL2CPP スクリプトバックエンドを使用する場合にのみ使用できます。
Faster runtime ランタイムのパフォーマンス用に最適化されたコードを生成します。この設定はデフォルトで有効になっています。
Faster (smaller) builds ビルドサイズとイテレーションに重点を置いて最適化されたコードを生成します。生成されるコードが少なくなり、ビルドも小さくなりますが、汎用コードに関してランタイムのパフォーマンスが低下する場合があります。このオプションは、変更を加えて反復処理を行う場合など、ビルド時間の短縮が重要な場合に使用してください。
C++ Compiler Configuration IL2CPP で生成されたコードのコンパイル時に使用する C++ コンパイラーの設定を選択します。
ノート: このプロパティは、 Scripting BackendIL2CPP に設定されている場合以外は無効になります。
Use incremental GC インクリメンタルガベージコレクターを使用します。これは、ガベージコレクションを複数のフレームに分散させることで、フレーム持続時間中の、ガベージコレクション関連のスパイクを減らすものです。詳細は Automatic Memory Management を参照してください。
Allow downloads over HTTP HTTP 経由でのコンテンツのダウンロードを許可するかどうか指定します。選択可能なオプションは Not allowedAllowed in Development builds onlyAlways allowed です。デフォルトのオプションは Not allowed です。これは、より安全なプロトコルである HTTPS が推奨されるためです。
Active Input Handling ユーザーからの入力をどのように処理するか選択します。
Input Manager (old) デフォルトの Input ウィンドウを使用します。
Input System Package (New) 新しい Input システムを使用します。新しい Input System の使用を試すには、InputSystem パッケージ をインストールしてください。
Both Use both systems side by side.

Shader Variant Loading

これらの設定を使用して、ランタイムにシェーダーが使用するメモリの量を制御します。

プロパティ 説明 
Default chunk size (MB) 全てのプラットフォームに対して、ビルドされたアプリケーション内に Unity が保存する圧縮シェーダーバリアントデータチャンクの最大サイズを設定します。デフォルトは 16 です。詳細は シェーダーロード を参照してください。
Default chunk count 全てのプラットフォームに対して、Unity がメモリに保持する解凍チャンク数のデフォルト制限を設定します。デフォルトは 0 で、これは制限がないことを意味します。
Override このビルドターゲットの Default chunk sizeDefault chunk count のオーバーライドを有効にします。
Chunk size (MB) このビルドターゲットの Default chunk size (MB) の値をオーバーライドします。
Chunk count このビルドターゲットの Default chunk count の値をオーバーライドします。

API Compatibility Level

すべてのターゲットに対する Mono の API Compatibility Level (API 互換性レベル) を選択できます。時にはサードパーティ製の .NET ライブラリが、.NET 互換性レベル外の機能を使用することがあります。そのような場合に何が起きているか理解し、最良の修正処理を行うためには、以下を試みると良いでしょう。

  1. Windows 用 ILSpy をインストールします。
  2. API 互換性レベルに問題が疑われる .NET アセンブリを ILSpy にドラッグします。これらは Frameworks/Mono/lib/mono/YOURSUBSET/にあります。
  3. サードパーティ製のアセンブリをドラッグします。
  4. サードパーティ製のアセンブリを右クリックし、Analyze を選択します。
  5. 分析レポートの中で、Depends on セクションを調べます。サードパーティ製品依存でありながら、選択した .NET 互換性レベルで対応しないものはすべてここで赤字でハイライトされます。

Script Compilation

WebGL プラットフォーム用のスクリプトのコンパイル設定
WebGL プラットフォーム用のスクリプトのコンパイル設定
プロパティ 説明 
Scripting Define Symbols カスタムコンパイルフラグを設定します。

詳細は 条件付きコンパイル を参照してください。
Additional Compiler Arguments 追加的な引数を Roslyn コンパイラーに渡すために、このリストにエントリーを追加します。追加の引数それぞれに対して新しいエントリーを 1 つ使用します。
新しいエントリーを作成するには、Add (+) をクリックしてください。エントリーを削除するには Remove (-) をクリックしてください。

全ての引数を追加し終えたら、Apply をクリックして追加的な引数を未来のコンパイルに含めます。Revert をクリックすると、このリストが最後に適用された状態にリセットされます。
Suppress Common Warnings C# の警告 CS0169 および CS0649 を表示するかどうかを示します。
Allow ‘unsafe’ Code 事前に定義されたアセンブリ (例えば Assembly-CSharp.dll) の ‘unsafe’ C# コード をコンパイルするサポートを有効にします。
アセンブリ定義ファイル (.asmdef) の場合、.asmdef ファイルの 1 つをクリックし、表示されたインスペクターウィンドウでオプションを有効にします。
Use Deterministic Compilation Indicates whether to prevent compilation with the -deterministic C# flag. With this setting enabled, compiled assemblies are byte-for-byte the same each time they’re compiled.

For more information, refer to C# Compiler Options that control code generation.

Optimization

WebGL プラットフォームの Optimization 設定
WebGL プラットフォームの Optimization 設定
Property Description
Prebake Collision Meshes Adds collision data to Meshes at build time.
Preloaded Assets Sets an array of Assets for the player to load on startup.
To add new Assets, increase the value of the Size property and then set a reference to the Asset to load in the new Element box that appears.
Strip Engine Code Enable this option if you want the Unity Linker tool to remove code for Unity Engine features that your Project doesn’t use. This setting is only available with the IL2CPP scripting backend. Most apps do not use every available DLL. This option strips out DLLs that your app doesn’t use to reduce the size of the built Player. If your app is using one or more classes that would normally be stripped out under your current settings, Unity displays a debug message when you try to build the app.
Managed Stripping Level Chooses how aggressively Unity strips unused managed (C#) code. When Unity builds your app, the Unity Linker process can strip unused code from the managed DLLs your Project uses. Stripping code can make the resulting executable smaller, but can sometimes remove code that’s in use.

For more information about these options and bytecode stripping with IL2CPP, refer to ManagedStrippingLevel.
Minimal Use this to strip class libraries, UnityEngine, Windows Runtime assemblies, and copy all other assemblies.
Low Remove unreachable managed code to reduce build size and Mono/IL2CPP build times.
Medium Run UnityLinker to reduce code size beyond what Low can achieve. You might need to support a custom link.xml file, and some reflection code paths might not behave the same.
High UnityLinker will strip as much code as possible. This will further reduce code size beyond what Medium can achieve but managed code debugging of some methods might no longer work. You might need to support a custom link.xml file, and some reflection code paths might not behave the same.
Enable Internal Profiler (Deprecated) This feature is deprecated and will be retired in a future version of Unity. Use the Profiler window instead (menu: Window > Analytics > Profiler).

The Profiler collects application performance data and prints a report to the console. The report contains the number of milliseconds each Unity subsystem takes to execute on each frame, averaged across 30 frames.
Vertex Compression Sets vertex compression per channel. This affects all the meshes in your project.
Typically, Vertex Compression is used to reduce the size of mesh data in memory, reduce file size, and improve GPU performance.

For more information on how to configure vertex compression and limitations of this setting, refer to Compressing mesh data.
Optimize Mesh Data Enable this option to strip unused vertex attributes from the mesh used in a build. This option reduces the amount of data in the mesh, which can help reduce build size, loading times, and runtime memory usage.

Warning: If you have this setting enabled, don’t change material or shader settings at runtime.

For more information, refer to PlayerSettings.stripUnusedMeshComponents.
Texture MipMap Stripping Enables mipmap stripping for all platforms. It strips unused mipmaps from Textures at build time.
Unity determines unused mipmaps by comparing the value of the mipmap against the quality settings for the current platform. If a mipmap value is excluded from every quality setting for the current platform, then Unity strips those mipmaps from the build at build time. If QualitySettings.masterTextureLimit is set to a mipmap value that has been stripped, Unity will set the value to the closest mipmap value that hasn’t been stripped.

Stack Trace

WebGL プラットフォームのロギング設定を選択します。

WebGL プラットフォームの Logging 設定
WebGL プラットフォームの Logging 設定
  • 必要なロギングのタイプに基づいて各ログタイプ (ErrorAssertWarningLogException) に対応するオプションを有効にして、好みのスタックトレース方法を設定します。
    • ScriptOnly: スクリプト実行時にのみログを記録します。
    • Full: 常にログを記録します。
    • None: ログは記録されません。

詳しくは、スタックトレースロギング を参照してください。

Legacy

Clamp BlendShapes (Deprecated) オプションを有効にすると、Skinned Mesh Renderer でブレンドシェイプのウェイトの範囲を固定できます。

WebGL プラットフォームの Legacy 設定
WebGL プラットフォームの Legacy 設定

Publishing settings

Publishing 設定を使用して、Unity が WebGL アプリケーションをビルドする方法を設定します。例えば、ブラウザのキャッシュを有効にして、ビルドにそのファイルを保存するように選択できます。

WebGL プラットフォームの Publishing 設定
WebGL プラットフォームの Publishing 設定
設定 機能
Enable Exceptions Choose how to handle unexpected code behavior (generally considered errors) at run time. The options are: None, Explicitly Thrown Exceptions Only, Full Without Stacktrace, and Full With Stacktrace. See the Building and running a WebGL project page for details.
Compression Format Choose the compression format to use for release build files. The options are: Gzip, Brotli, and Disabled (none). Note that this option doesn’t affect development builds.
Name Files As Hashes これを有効にすると、ビルドの各ファイルのファイル名として非圧縮ファイルコンテンツの MD5 ハッシュを使用できます。
Data caching これを有効にすると、自動的にコンテンツのアセットデータをユーザーマシン上にキャッシュします。そのため、(コンテンツが変更されない限り) その後の実行で再度ダウンロードする必用がありません。
Caching は、ブラウザーによって提供される IndexedDB API を使用して実装されます。ブラウザーによっては、あるサイズを超えるデータをキャッシュする時にユーザーの許可を求める、などの IndexedDB API 関連の制限を実装している場合があります。
Debug Symbols これを有効にすると、エラーが発生したときにデバッグシンボルを保持し、スタックトレースのデマングル (元の関数名を表示) を実行します。リリースビルドでは、すべてのデバッグ情報が別々のファイルに格納され、エラーが発生したときにオンデマンドでサーバーからダウンロードされます。開発ビルドには、メインモジュールに埋め込まれたデマングルサポートが常にあるため、このオプションの影響を受けません。
Show Diagnostics Overlay これを有効にすると、WebGL ビルドで診断情報を表示するオーバーレイが表示されます。開発版とリリース版の両方で使用できます。詳細については、診断オーバーレイプレイヤー設定を表示 を参照してください。
Decompression Fallback ローダーにビルドファイルの解凍フォールバックコードを加えます。選択した圧縮方法に従ってサーバーの応答ヘッダーを設定できない場合は、このオプションを使用します。
Initial Memory Size WASM ヒープメモリの初期サイズをメガバイト (MB) で指定します。デフォルトでは 32 MB に設定されています。Memory Growth ModeNone に設定されている場合、これは WASM ヒープメモリの最大サイズでもあります。
Memory Growth Mode WASM ヒープメモリの成長モードを以下のオプションから選択します。推奨オプションは Geometric です。
None WASM のヒープメモリは、Initial Memory Size で設定された固定サイズです。
Linear WASM のヒープメモリは、Linear Memory Growth Step で設定された固定量を増加します。
Geometric WASM のヒープメモリは、Geometric Memory Growth StepGeometric Memory Growth Cap で設定された係数に応じて、現在のヒープサイズに相対的に増加します。
Power Performance Helps you determine the performance mode that’s ideal for your GPU configuration in a multi-GPU systems environment for WebGL implementation. Select the best GPU configuration for your WebGL build:
Default Select Default if you want the WebGL implementation to use its default behavior.
Low Performance Select Low Performance if you want the WebGL implementation to prioritize power savings.
High Performance Select High Performance, if you want the WebGL implementation to prioritize rendering performance.
Maximum Memory Size WAS のヒープメモリの最大サイズを MB 単位で指定します。デフォルトでは 2048 MB に設定されています。このオプションは、Memory Growth ModeLinear、または Geometric の場合のみ有効です。
Linear Memory Growth Step WASM ヒープ拡張ステップを MB 単位で制御するための高度な調整オプションです。デフォルトで 16 MB に設定されています。16 MB の拡張ステップは、ヒープ拡張の必要があるたびに 16 MB ずつ拡張されることを意味します。
Geometric Memory Growth Step 現在のヒープ サイズに応じて WASM ヒープ拡張ファクターを制御するための高度な調整オプションです。デフォルトで、0.2 に設定されています。拡張ファクター 0.2 は、ヒープ拡張の必要があるたびに、ヒープのサイズが 0.2 * currentHeapSize ずつ拡張することを意味します。
Geometric Memory Growth Cap ヒープ拡張ステップの上限を MB 単位で制御する高度な調整オプションです。デフォルトで、96 MB に設定されています。拡張上限 96 MB は、ヒープサイズの拡張が最大で 96 MB であることを意味します。Memory Growth ModeGeometric に設定されている場合にのみ利用可能です。

診断オーバーレイの表示設定

WebGL ビルドの最適化と潜在的な問題の診断のために、この設定を有効にすると診断情報 (現在はメモリ使用量に限定) を表示できます。有効にすると、ビルドにアイコンが表示され、ビルドに関する有用なデータがオーバーレイ表示されます。開発用ビルドとリリース用ビルドの両方で利用できます。

  1. 診断情報を表示するには、Player 設定ウィンドウで Show Diagnostics Overlay オプションを有効にします (File > Build Settings > Player Settings > Publishing Settings)。

    デスクトップでは、WebGL キャンバスのフッターに診断アイコンが表示されます。

    キャンバスのフッターにある診断ボタン
    キャンバスのフッターにある診断ボタン

    モバイルデバイスでは、画面右下に診断アイコンが表示されます。

    診断ボタンを表示するアンドロイド携帯
    診断ボタンを表示するアンドロイド携帯
  2. 診断 アイコン をクリックします。JavaScript のメモリを示すオーバーレイが表示され、さらに WASM のヒープメモリ使用量が表示されます。

診断オーバーレイは、Javascript のメモリ分布と WASM のヒープメモリ使用量を表示します。
診断オーバーレイは、Javascript のメモリ分布と WASM のヒープメモリ使用量を表示します。

以下の診断がオーバーレイ画面に表示されます。

プロパティ 機能
Total JS Memory The current size of the JavaScript (JS) heap, including unused memory not allocated to any JS objects in megabytes.
Used JS Memory Memory in use by JS objects in megabytes.
Total WASM heap memory Linear memory representing the entire heap of the C/C++ Unity engine that’s compiled with Emscripten, including unallocated memory in megabytes.
Used WASM heap The space of the WASM heap that’s allocated in megabytes.
Page Load Time to First Frame The total time from the beginning of page load until the first application frame rendering is complete in milliseconds.
Page Load Time The time it takes from page load to get to the beginning of rendering the first frame, including downloads, compilation, parsing, and the main application in milliseconds.
Code download time The time it takes for the build to download the code file in milliseconds.
Load time of asset file(.data) The time it takes for the build to download the .data file binary, in milliseconds.
WebAssembly startup time The time it takes between loading the JavaScript framework and reaching Unity’s C++ main(). This is close to compilation time of WASM, in milliseconds.
Game startup time The time it takes to finish executing Unity’s C++ main() to the first frame of main, which typically contains the loading of the first game scene in milliseconds.
Average FPS (10 seconds) The average of last 10 frames per second.
Current frames per second The number of frames rendered on screen per second.
Number of Frame Stalls The number of rendered frames that took unusually long to complete compared to their previous frames.

JS メモリに関する重要点

JS メモリの情報は、performance.memory API を使用して取得されます。この API は現在、Chrome または Edge でのみサポートされています。Safari や Firefox でこの情報を返す API はありません。

Note: The performance.memory API isn’t supported on iOS devices.

この API がサポートされていないブラウザーでは、使用不可を示すメッセージが表示されます。

performance.memory API をサポートしないブラウザーでは、使用不可を示すメッセージが表示されます。
performance.memory API をサポートしないブラウザーでは、使用不可を示すメッセージが表示されます。

その他の参考資料

PlayerSettingsWebGL

WebGL development
Interaction with browser scripting