Use the following recommended Player settings to optimize your builds for the Unity WebGLA JavaScript API that renders 2D and 3D graphics in a web browser. The Unity WebGL build option allows Unity to publish content as JavaScript programs which use HTML5 technologies and the WebGL rendering API to run Unity content in a web browser. More info
See in Glossary platform.
Find these settings under Edit > Project settings > Player. For more information on each setting, refer to the details in Player settingsSettings that let you set various player-specific options for the final game built by Unity. More info
See in Glossary.
Setting | Recommended Setting | Description |
---|---|---|
API Compatibility Level | .NET Standard 2.1 | Produces smaller builds. |
IL2CPP Code Generation | Faster (smaller) builds | Generates code optimized for build size and iteration. |
Managed Stripping Level | High | Unity does a high level of managed stripping to create a smaller build. |
Configure the following recommended settings in the Publishing Settings section:
Setting | Recommended Setting | Description |
---|---|---|
Enable Exceptions | None | Exceptions can cause overhead. |
Compression Format | Brotli | Files compressed by Brotli are smaller. |
Data Caching | Enabled | Runs faster since cached data doesn’t need to be downloaded again on subsequent runs (unless the contents have changed). |
Debug Symbols | Off | Debug symbols can slow down your application. |
Use the API Compatibility Level setting to choose which .NET APIs you can use in your project. The recommended setting is .Net Standard 2.1 because this setting produces smaller builds and has cross-platform support. However, you need to check if your platform fully supports .Net Standard 2.1. For other options, refer to WebGL player settings.
To change the API Compatability Level via script instead, add this code to one of your scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary:
PlayerSettings.SetApiCompatibilityLevel(namedBuildTarget, ApiCompatibilityLevel.NET_2_0);
Use the IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary Code generation setting to configure how Unity manages IL2CPP code generation (if your project uses the IL2CPP scripting backend).
The Faster (smaller) builds option is recommended because it creates a smaller build and generates less code which results in faster build times. Faster build times are vital in WebGL applications. However, this setting can reduce runtime performance.
For more information, refer to IL2CPP overview.
To enable this setting via script instead, add this code to one of your scripts:
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget,
Il2CppCodeGeneration.OptimizeSize);
Use Managed stripping level to configure how much the Unity linker process strips unused code from the managed DLLs your project uses. The recommended setting is High because stripping code can make your executable significantly smaller, which is very important in WebGL applications. However, possible side effects may include:
Managed code debugging of some methods may no longer work.
You may need to maintain a custom link.xml file.
Some reflection code paths may not behave the same.
For more information, refer to Managed code stripping.
To change this setting via script instead, add this code to one of your scripts:
PlayerSettings.SetManagedStrippingLevel(namedBuildTarget,
ManagedStrippingLevel.High);
Choose what compressionA method of storing data that reduces the amount of storage space it requires. See Texture Compression, Animation Compression, Audio Compression, Build Compression.
See in Glossary format to use for release build files. Brotli is the recommended setting because it has the best compression ratios and Brotli-compressed files are smaller than gzip. Smaller files are best for WebGL applications. However, Chrome and Firefox only support Brotli if the user accesses the site over HTTPS. Also, although Brotli is supported on most modern servers, there are some servers that do not support it. Make sure that your server supports Brotli.
For more information on compression formats, refer to Deploy a WebGL application.
To enable this setting via script instead, add this code to one of your scripts:
PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Brotli;
Enable Data caching so that Unity caches your contents asset data on the user’s machine. Data caching can make the application run faster. For more information, refer to Cache behavior in Web.
To enable this setting via script instead, add this code to one of your scripts:
PlayerSettings.WebGL.dataCaching = true;
The Debug symbols setting preserves debug symbols and displays original function names of the stack trace when an error occurs, so it’s easier to identify the source of an error. It is recommended that you turn off the Debug symbols option on your final release build because it can make your build unnecessarily large and slow down your application. Enable this setting during development and testing to make it easier to identify the source of an error.
To deactivate this setting via script instead, add this code to one of your scripts:
PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Off;
The Enable exceptions setting lets you choose how to handle errors at runtime. It is recommended that you choose the None option in your final release build because this setting gives the best performance and smallest builds.
However, with this option, any exception thrown causes your content to stop with an error, so it’s best to enable exceptions during development and testing. For more information, refer to Build your WebGL application and WebGL Player settings.
To deactivate exceptions via script instead, add this code to one of your scripts:
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;