To create a build for WebGL, go to File > Build Settings from Unity’s main menu. In the Platform list, select WebGL and then click Switch Platform.
When you have configured the Build Settings, choose one the following options:
The Unity build system for WebGL supports the following settings:
|The texture compression format to use for the build. For more information, refer to WebGL texture compression. The available options are:
|Use Player Settings
|This is the default selection. It uses the texture compression format you set in the Player settings window.
|Uses ETC2 format, which is widely supported on mobile devices.
|Uses ASTC format, which is widely supported on mobile devices.
|Uses DXT format, which is widely supported on desktop devices.
|Enable this setting to include scripting debug symbols and the Profiler in your build. When you enable this, Unity sets the
DEVELOPMENT_BUILD scripting define. Use this setting only when you want to test your application because development builds don’t minify content, they’re large to distribute.
|Select the optimization mode to use for compiling the WebGL code.
|This is the default setting. Select this to generate WebGL code that’s optimized for runtime performance.
|Select this to generate WebGL code that’s optimized for build size. This is useful for reducing WebGL games to the smallest downloadable size, and for large projects if a mobile browser (Android or iOS) refuses to load the default optimize-for-speed WebAssembly builds as too large for mobile devices to consume.
|Typically, when enabled, this setting allows you to automatically connect the Unity Profiler to your build. However for WebGL, as you can’t connect the Profiler to a running build, use this option to connect the content to the Editor instead. This is because the Profiler connection is handled using WebSockets on WebGL, but a web browser only allows outgoing connections from the content. For this setting to be available, you must enable the Development Build option.
|Enable this setting to activate Deep Profiling in the Profiler. This makes the Profiler instrument every function call in your application and returns more detailed profiling data. When you enable Deep Profiling Support, it might slow down script execution. This option is only available if you enable the Development Build option.
|Use it to build your application.
|Build And Run
|Use it to view the WebGL Player locally. Unity uses a local web server to host your build, and opens it from a localhost URL. Alternatively, you can use a custom local web server with properly configured response headers. For more information, see Compressed builds and server configuration.
For changing the settings for Asset Import Overrides, refer to Build Settings.
Build folder has the following files, where
[ExampleBuild] represents the name of the target build folder.
|A binary image to initialize the heap memory for your Player. Unity generates this file for multi-threaded WebAssembly builds only.
|エラーのスタックトレースを解除するのに必要なデバッグシンボル名。このファイルは、Debug Symbols オプション (File > Build Settings > Player Settings) を有効にする場合、リリースビルドに対してのみ生成されます。
|A background image, which displays while the build is loading. This file is only generated when a Background Image is available in the Player Settings (File > Build Settings > Player Settings > Splash Image). For more information, see Splash Screen.
If you enable a Compression Method for your build, Unity identifies the extension that corresponds with the compression method and adds this extension to the names of the files inside the Build sub folder. If you enable Decompression Fallback, Unity appends the extension
.unityweb to the build file names. Otherwise, Unity appends the extension
.gz for the Gzip compression method, or
.br for the Brotli compression method.
For more information, refer to Compressed builds and server configuration.
If you enable Name Files As Hashes in the Player Settings, Unity uses the hash of the file content instead of the default file name. This applies to each file in the build folder. This option allows you to upload updated versions of the game builds into the same folder on the server, and only upload the files which have changed between build iterations.
ノート: ファイルシステムから直接プレイヤーを開くと、ブラウザーによっては動作しないことがあります。これは、ローカルファイルの URL に適用されるセキュリティ制限によるものです。
Use Enable Exceptions to specify how unexpected code behavior (also known as errors) is handled at runtime. To access Enable Exceptions, go to the Publishing Settings section in WebGL Player Settings.
It has the following options:
throw statement in your scripts and to also ensure
throw statements in your scripts (the same as in the Explicitly Thrown Exceptions Only option)