Use the following recommended Player settings to optimize your builds for the Unity Web 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 |
---|---|---|
Compression Format | Brotli | Files compressed by Brotli are smaller. |
Data Caching | Enabled | Runs faster because 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. |
Enable Exceptions | None | Enable Target WebAssembly 2023 instead for exceptions without overhead. |
Target WebAssembly 2023 | Enable | The Web Assembly 2023 feature setA feature set is a collection of related packages that you can use to achieve specific results in the Unity Editor. You can manage feature sets directly in Unity’s Package Manager. More info See in Glossary contains features that help optimize your project. |
Maximum Memory Size (MB) | Enter the amount of memory you need in MB. | Unity Web supports up to 4096 MB of memory for your build. |
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 Web player settings.
To change the API Compatibility 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 back end).
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 Web 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 important in Web applications. However, possible side effects might include:
Managed code debugging of some methods might not work.
You might need to maintain a custom link.xml
file.
Some reflection code paths might 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 Web applications. However, Chrome and Firefox only support Brotli if the user accesses the website over HTTPS. Also, although most modern servers support Brotli, some servers don’t support it. Make sure that your server supports Brotli.
For more information on compression formats, refer to Deploy a Web 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. The recommended best practice is to disable Debug symbols 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. The recommended best practice is to 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 Web Player settings.
To deactivate exceptions via script instead, add this code to one of your scripts:
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;
WebAssembly 2023 is a selection of WebAssembly language features that can improve performance and reduce code size. Therefore, it is recommended that you enable this setting.
To enable this setting via script instead, add this code to one of your scripts:
PlayerSettings.WebGL.wasm2023 = true;
// PlayerSettings.WebGL.webAssemblyTable = true;
// PlayerSettings.WebGL.webAssemblyBigInt = true;
To enable the WebAssembly.Table
or BigInt
features without WebAssembly 2023, remove the first line of code and remove the comment lines.
Unity supports up to 4096 MB of memory for your build. For most applications, 2048 MB of memory is enough. But for more complex real-time 3D experiences, especially for desktop browsers, it’s better to have more memory. With more memory, you can load in richer, larger scenesA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary more dynamically.
However, there are known bugs for builds over 2048 MB in Firefox and Chrome browsers before version 119.
To change the maximum memory via script instead, add this code to your script and change the number to your preferred memory size:
PlayerSettings.WebGL.maximumMemorySize = 4096;
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.