Version: 2021.3
Language : English
WebGL development
Interaction with browser scripting

WebGL Player settings

This page details the Player settings specific to the 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. For a description of the general Player settings, see Player settings.

WebGL Player settings
WebGL Player settings

You can find documentation for the properties in the following sections:

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

For more information about WebGL Publishing Settings, see WebGL Building and Running.

Resolution and Presentation

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

Resolution section for the WebGL Player platform
Resolution section for the WebGL Player platform

Resolution

Setting Function
Default Canvas Width Set the width of the WebGL canvas element.
Default Canvas Height Set the height of the WebGL canvas element.
Run In Background Enable this option to allow your content to continue to run when the canvas or the browser window loses focus.

WebGL Template

Select a template to use for your WebGL Project:

  • The Default page is a simple white page with a loading bar on a grey canvas.
  • The Minimal page has only the necessary boilerplate code to run the WebGL content.

You can specify your own template so that you can run your game in a similar environment to the finished game. Follow the instructions in Using WebGL Templates.

Splash Image

Use the Virtual Reality Splash Image setting to select a custom splash image for XRAn umbrella term encompassing Virtual Reality (VR), Augmented Reality (AR) and Mixed Reality (MR) applications. Devices supporting these forms of interactive applications can be referred to as XR devices. More info
See in Glossary
displays. For information on common Splash Screen settings, see Splash Screen.

Splash screen settings for virtual reality.
Splash screen settings for virtual reality.

Other Settings

This section allows you to customize a range of options organized into the following groups:

Rendering

Use these settings to customize how Unity renders your game for the WebGL platform.

Rendering Player settings for the WebGL platform
Rendering Player settings for the WebGL platform
Property Description
Color Space Choose which color space Unity uses for rendering: Gamma or Linear. For more information, see Linear rendering overview.

Gamma: Gamma color space is typically used for calculating lighting on older hardware restricted to 8 bits per channel for the frame buffer format. Even though monitors today are digital, they might still take a gamma-encoded signal as input.

Linear: Linear color space rendering gives more precise results. When you select to work in linear color space, the Editor defaults to using sRGB sampling. If your Textures are in linear color space, you need to work in linear color space and disable sRGB sampling for each Texture.
Auto Graphics API Disable this option to manually pick and reorder the graphics APIs. By default this option is enabled, and Unity includes WebGL2.0, with WebGL1.0 as a fallback for devices where WebGL2.0 is not supported.
Static Batching Use Static batching. For more information, refer to Draw call batching.
Dynamic Batching Use dynamic batching (enabled by default). For more information, refer to Draw call batching.

Note: Dynamic batching has no effect when a Scriptable Render Pipeline is active, so this setting is only visible if the Scriptable Render Pipeline Asset Graphics setting is blank.
Graphics Jobs Offloads graphics tasks (render loops) to worker threads running on other CPU cores. This option reduces the time spent in Camera.Render on the main thread, which can be a bottleneck.
Lightmap Encoding Defines the encoding scheme and compression format of the lightmaps.
You can choose from Low Quality, Normal Quality, or High Quality.
Lightmap Streaming Uses Mipmap Streaming for lightmaps. Unity applies this setting to all lightmaps when it generates them.

Note: To use this setting, you must enable the Texture Streaming Quality setting.
Streaming Priority Sets the priority for all lightmaps in the Mipmap Streaming system. Unity applies this setting to all lightmaps when it generates them.
Positive numbers give higher priority. Valid values range from –128 to 127.
Frame Timing Stats Allows Unity to gather CPU/GPU frame timing statistics. Use this option with the Dynamic ResolutionA Camera setting that allows you to dynamically scale individual render targets, to reduce workload on the GPU. More info
See in Glossary
camera setting to determine if your application is CPU or GPU bound.
Virtual Texturing (Experimental) Enable this option to reduce GPU memory usage and texture loading times if your Scene has many high resolution textures. For more information, refer to Virtual Texturing.

Note: The Unity Editor requires a restart for this setting to take effect.
Shader precision model Controls the default precision of samplers used in shaders. For more information, see Shader data types and precision.
360 Stereo Capture Allows Unity to capture stereoscopic 360 images and videos. When enabled, Unity compiles additional shader variants to support 360 capture (only on Windows). When enabled, the enable_360_capture keyword is added during the Stereo RenderCubemap call. This keyword isn’t triggered outside the Stereo RenderCubemap function.

For more information, refer to Stereo 360 Image and Video Capture.

Configuration

Configuration settings for the WebGL platform
Configuration settings for the WebGL platform
Property Description
Scripting Backend The scripting backend determines how Unity compiles and executes C# code in your Project. This setting defaults to IL2CPP for Universal Windows Platform and can’t be changed.
API Compatibility Level Choose which .NET APIs you can use in your project. This setting can affect compatibility with third-party libraries. However, it has no effect on Editor-specific code (code in an Editor directory, or within an Editor-specific Assembly Definition).

Tip: If you are having problems with a third-party assembly, you can try the suggestion in the API Compatibility Level section below.
.Net Framework Produces larger builds and any additional APIs available are not necessarily supported on all platforms. Choose this option when using libraries that access APIs not included in .NET Standard 2.0. Compatible with the .NET Framework 4 (which includes everything in the .NET Standard 2.0 profile as well as additional APIs).

For more information, see Referencing additional class library assemblies.
.Net Standard 2.1 Produces smaller builds and has full cross-platform support.
C++ Compiler Configuration Chooses the C++ compiler configuration used when compiling IL2CPP generated code.

Note: This property is disabled for the Universal Windows Platform because it’s chosen in the generated Visual Studio project.
Use incremental GC Uses the incremental garbage collector, which spreads garbage collection over several frames to reduce garbage collection-related spikes in frame duration.

For more information, see Automatic Memory Management.
Assembly Version Validation Indicates whether Mono validates types from a strongly-named assembly.
Accelerometer Frequency Defines how often to sample the accelerometer. If you choose Disabled, then no samples are taken. Otherwise, you can choose from 15Hz, 30Hz, 60Hz and 100Hz frequencies.
Active Input Handling Choose how to handle input from users.
Input Manager (Old) Uses the traditional Input settings.
Input System Package (New) Uses the Input system. This option requires you to install the InputSystem package.
Both Use both systems side by side.

API Compatibility Level

You can choose your mono API compatibility level for all targets. Sometimes a 3rd-party .NET library uses functionality that’s outside of your .NET compatibility level. To understand what’s going on in such cases, and how to best fix it, try following these suggestions:

  1. Install ILSpy for Windows.
  2. Drag the .NET assemblies for the API compatilibity level that you are having issues with into ILSpy. You can find these under Frameworks/Mono/lib/mono/YOURSUBSET/.
  3. Drag in your 3rd-party assembly.
  4. Right-click your 3rd-party assembly and select Analyze.
  5. In the analysis report, inspect the Depends on section. The report highlights anything that the 3rd-party assembly depends on, but that is not available in the .NET compatibility level of your choice in red.

Script Compilation

Script compilation settings for the WebGL platform
Script compilation settings for the WebGL platform
Property Description
Scripting Define Symbols Sets custom compilation flags.

For more details, see Platform dependent compilation.
Additional Compiler Arguments Adds entries to this list to pass additional arguments to the Roslyn compiler. Use one new entry for each additional argument.
To create a new entry, click Add (+). To remove an entry, click Remove (-).

When you have added all desired arguments, click Apply to include your additional arguments in future compilations. Click Revert to reset this list to the most recent applied state.
Suppress Common Warnings Indicates whether to display the C# warnings CS0169 and CS0649.
Allow ‘unsafe’ Code Enables support for compiling ‘unsafe’ C# code in a pre-defined assembly (for example, Assembly-CSharp.dll).
For Assembly Definition Files (.asmdef), click on one of your .asmdef files and enable the option in the Inspector window that appears.
Use Deterministic Compilation Indicates whether to prevent compilation with the -deterministic C# flag. With this setting enabled, compiled assemblies are byte-for-byte identical each time they are compiled.

For more information, see Microsoft’s deterministic compiler option.
Enable Roslyn Analyzers Indicates whether to compile user-written 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
without Roslyn analyzer DLLs that might be present in your project.

Optimization

Optimization settings for the WebGL platform

Property Description
Prebake Collision Meshes Adds collision data to Meshes at build time.
Keep Loaded Shaders Alive Indicates whether to prevent shaders from being unloaded.

For more information, see Shader Loading.
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.
Managed Stripping Level Chooses how aggressively Unity strips unused managed (C#) code. The options are Minimal, Low, Medium, and High.
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 significantly smaller, but can sometimes accidentally remove code that’s in use.

For more information about these options and bytecode stripping with IL2CPP, refer to ManagedStrippingLevel.
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, refe 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, you should remember to not change material or shader settings at runtime.

For more information, refer to PlayerSettings.stripUnusedMeshComponents.
Texture MipMap Stripping Enables mipmap stripping for all platforms. This 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 has not been stripped.

Logging

Select what type of logging to allow in specific contexts.

Logging settings for the WebGL platform
Logging settings for the WebGL platform
  • Select your preferred stack trace method by enabling the option that corresponds to each Log Type (Error, Assert, Warning, Log, and Exception) based on the type of logging you require. For example:
    • ScriptOnly: Logs only when running scripts.
    • Full: Logs all the time.
    • None: No logs are ever recorded.

See stack trace logging for more information.

Legacy

Enable the Clamp BlendShapes (Deprecated) option to clamp the range of blend shape weights in Skinned Mesh Renderers.

Legacy settings for the WebGL platform
Legacy settings for the WebGL platform

Publishing settings

Use the Publishing Settings to configure how Unity builds your WebGL app. For example, you can choose to enable the browser cache to store its files in your build.

Publishing settings for the WebGL platform
Publishing settings for the WebGL platform
Setting Function
Enable Exceptions Choose how to handle unexpected code behavior (generally considered errors) at runtime. The options are: None, Explicitly Thrown Exceptions Only, Full Without Stacktrace, and Full With Stacktrace. For more information, refer to Building and running a WebGL project.
Compression Format Choose the 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. The options are: Gzip, Brotli, and Disabled (none). Note that this option doesn’t affect development buildsA development build includes debug symbols and enables the Profiler. More info
See in Glossary
.
Name Files As Hashes Enable this option to use an MD5 hash of the uncompressed file contents as a filename for each file in the build.
Data caching Enable this option to automatically cache your contents Asset data on the user’s machine so it doesn’t have to be re-downloaded on subsequent runs (unless the contents have changed).
Caching is implemented using the IndexedDB API provided by the browser. Some browsers might implement restrictions around this, such as asking the user for permission to cache data over a specific size.
Debug Symbols Select from the available options to specify how debug symbols are added in your build.
Off Select this option if you don’t want any debug symbols to be added in your build.
External Select this option to store the debug symbols to in a separate file that you can download from the server when an error occurs. It’s recommended to choose this option for release builds.
Embedded Select this option to embed the debug symbols in a WASM file. This option helps preserve debug symbols and perform demangling (displaying the original function names) of the stack trace when an error occurs. By default, demangling support is available for this option.
Decompression Fallback Include decompression fallback code for build files in the loader. Use this option if you are unable to configure server response headers according to the selected compression method.

Additional resources:

PlayerSettingsWebGL

WebGL development
Interaction with browser scripting
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961