Version: 2022.1
Getting started with WebGL development
Texture Compression in WebGL

WebGL Player 设置

This page details the Player settings specific to the WebGL platform. For a description of the general Player settings, see Player settings.

WebGL Player 设置
WebGL Player 设置


Note: Although the Icon panel appears on the WebGL Player settings, there are no icon settings because WebGL games do not use icons.

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

Resolution and Presentation


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


设置 功能
Default Canvas Width 设置 WebGL 画布元素的宽度。
Default Canvas Height 设置 WebGL 画布元素的高度。
Run In Background 启用此选项将允许您的内容将在画布或浏览器窗口失去焦点时继续运行。

WebGL Template

选择要用于 WebGL 项目的模板:

  • Default 页面是一个简单的白色页面,其中的灰色画布上有一个加载进度条。
  • Minimal 页面只有必要的样板代码来运行 WebGL 内容。
  • The PWA page has a Progressive Web App including a web manifest file and service worker code.

您可以指定自己的模板,以便在与之前完成的游戏类似的环境中运行游戏。遵循使用 WebGL 模板中的说明。

Splash Image

Use the Virtual Reality Splash Image setting to select a custom splash image for XR 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



使用这些设置可自定义 Unity 针对 WebGL 平台渲染游戏的方式。

WebGL 平台的 Rendering Player 设置
WebGL 平台的 Rendering Player 设置
设置 功能
Color Space 选择应该用于渲染的颜色空间,选项为:_Gamma_ 或 Linear
Auto Graphics API 禁用此选项可手动选择和重新排序图形 API。默认情况下,此选项是启用的,并且 Unity 包含 WebGL2.0,对于不支持 WebGL2.0 的设备,以 WebGL1.0 作为后备选项。
Static Batching 启用此选项可使用静态批处理。
Dynamic Batching 选中此复选框可在构建中使用动态批处理(默认情况下启用)。
Graphics Jobs 启用此选项可指示 Unity 将图形任务(渲染循环)卸载到在其他 CPU 核心上运行的工作线程。此功能旨在减少主线程上 Camera.Render 所花费的时间,该时间通常成为瓶颈。
Texture compression format Choose DXT, ETC2 or ASTC to set the texture compression format for WebGL. See Texture compression format overview for more information on how to pick the right format.
Lightmap Encoding 选择 Low QualityNormal QualityHigh Quality 来设置光照贴图编码。此设置影响光照贴图的编码方案和压缩格式。
HDR Cubemap Encoding Choose Low Quality, Normal Quality, or High Quality to set the HDR Cubemap encoding. This setting affects the encoding scheme and compression format of the HDR Cubemaps.
Lightmap Streaming Enabled Whether to use 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 Set 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 启用此选项可收集 CPU/GPU 帧时序统计信息。
Virtual Texturing Indicates whether to enable 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. See Shader data types and precision for more details.
360 Stereo Capture Indicates whether Unity can capture stereoscopic 360 images and videos. When enabled, Unity compiles additional shader variants to support 360 capture (currently only on Windows/OSX). When enabled, enable_360_capture keyword is added during the Stereo RenderCubemap call. Note that this keyword is not triggered outside the Stereo RenderCubemap function. For more information, see Stereo 360 Image and Video Capture.


WebGL 平台的 Configuration 设置
WebGL 平台的 Configuration 设置
Property Description
Scripting Backend Choose the scripting backend you want to use. The scripting backend determines how Unity compiles and executes C# code in your Project.
Mono Compiles C# code into .NET Common Intermediate Language (CIL) and executes that CIL using a Common Language Runtime. For more information, see 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 run time. See IL2CPP for more information.
API Compatibility Level Choose which .NET APIs you can use in your project. This setting can affect compatibility with 3rd-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 Standard Compatible with .NET Standard 2.0. Produces smaller builds and has full cross-platform support.
.Net Framework Compatible with the .NET Framework 4 (which includes everything in the .NET Standard 2.0 profile as well as additional APIs). Choose this option when usng libraries that access APIs not included in .NET Standard 2.0. Produces larger builds and any additional APIs available are not necessarily supported on all platforms. See Referencing additional class library assemblies for more information.
IL2CPP Code Generation Defines how Unity manages IL2CPP code generation. This option is only available if you use the IL2CPP scripting backend.
Faster runtime Generates code optimized for runtime performance. This setting is enabled by default.
Faster (smaller) builds) Generates code optimized for build size and iteration. This setting generates less code and produces a smaller build, but may reduce runtime performance, especially for generic code. Use this option when faster build times are important, such as when iterating on changes.
C++ Compiler Configuration Choose the C++ compiler configuration used when compiling IL2CPP generated code.
Note: This property is disabled unless Scripting Backend is set to IL2CPP.
Use incremental GC Enable this to use the incremental garbage collector, which spreads garbage collection over several frames to reduce gc-related spikes in frame duration.
Allow downloads over HTTP Choose from the options below to allow downloading content over HTTP. The options are Not allowed, Allowed in Development builds only, and Always allowed. The default option is not allowed due to the recommended protocol being HTTPS, which is more secure.
Active Input Handling Choose how you want to handle input from users.
Input Manager (old) Use the default Input window.
Input System (Preview) Use the newer Input system. The Input System is provided as a preview package for this release. To try a preview of the Input System, 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 the problematic files under Frameworks/Mono/lib/mono/YOURSUBSET/. 3.拖入第三方程序集。 4.右键单击第三方程序集并选择 Analyze。 5.在分析报告中,检查 Depends on 部分。此报告以红色突出显示第三方程序集所依赖的但在您选择的 .NET 兼容性级别中不可用的任何内容。

Script Compilation

WebGL 平台的脚本编译设置
WebGL 平台的脚本编译设置
设置 功能
Scripting Define Symbols Set custom compilation flags. For more details, see the documentation on Platform dependent compilation.
Additional Compiler Arguments Add 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, press the ‘+’ button. To remove an entry, press the ‘-’ button.
When you have added all desired arguments, click the Apply button to include your additional arguments in future compilations.The Revert button resets this list to the most recent applied state.
Suppress Common Warnings Disable this setting to display the C# warnings CS0169 and CS0649.
Allow ‘unsafe’ Code 允许在预定义的程序集(例如,Assembly-CSharp.dll)中编译“不安全”的 C# 代码
对于程序集定义文件 (.asmdef),请单击其中一个 .asmdef 文件,并在出现的 Inspector 窗口中启用该选项。
Use Deterministic Compilation Disable this setting 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 documentation.
Enable Roslyn Analyzers Disable this setting to compile user-written scripts without Roslyn analyzer DLLs that might be present in your project.


WebGL 平台的 Optimization 设置
WebGL 平台的 Optimization 设置
Property Description
Prebake Collision Meshes Enable this option to add collision data to Meshes at build time.
Keep Loaded Shaders Alive When enabled, you cannot unload a shader. See Shader Loading for more information.
Preloaded Assets Set an array of Assets for the player to load on startup.
To add new Assets, increase the value of the Size property, then set a reference to the Asset to load in the new Element box that appears.
AOT compilation options Additional options for Ahead of Time (AOT) compilation. This helps optimize the size of the built iOS player.
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 don’t 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 Choose how Unity strips unused managed (C#) code.The options are Disabled 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 is in use. For more information about these options, see documentation on Managed code stripping.

For information about bytecode stripping with IL2CPP, see documentation on Managed bytecode stripping with IL2CPP.
Vertex Compression Choose the channel that you want to set for compressing meshes under the vertex compression method, which by default, is set to Mixed. 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 information on how to configure vertex compression and limitations of this setting, see [compressing meshes].
Optimize Mesh Data Selecting this option enables stripping of unused vertex attributes from the mesh used in a build.
This reduces the amount of data in the mesh, which might help reduce build size, loading times, and runtime memory usage. However, you must remember to not change material or shader settings at runtime, if you have this setting enabled. See PlayerSettings.stripUnusedMeshComponents for more information.
Texture MipMap Stripping Enable this option to enable mipmap stripping for all platforms, which 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.

Stack Trace

Select the logging settings for the WebGL platform.

WebGL 平台的 Logging 设置
WebGL 平台的 Logging 设置
  • Select your preferred logging method from the available options.

  • Check a box 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.


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

WebGL 平台的 Legacy 设置
WebGL 平台的 Legacy 设置

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.

WebGL 平台的 Publishing settings
WebGL 平台的 Publishing settings
设置 功能
Enable Exceptions 选择在运行时如何处理意外的代码行为(通常视为错误)。选项包括:_NoneExplicitly Thrown Exceptions OnlyFull Without Stacktrace_ 和 Full With Stacktrace。有关详细信息,请参阅构建和运行 WebGL 项目页面。
Compression Format 选择要用于发布版本文件的压缩格式。选项包括:_GzipBrotli_ 或 Disabled_(无)。请注意,此选项不会影响开发版本。 | |Name Files As Hashes||启用此选项可使用未压缩文件内容的 MD5 哈希作为构建中每个文件的文件名。| |Data caching||启用此选项可自动将内容资源数据缓存在用户计算机上,这样就不必在后续运行中重新下载(除非内容已更改)。
缓存是使用浏览器提供的 IndexedDB API 实现的。有些浏览器可能会对此实施限制,例如要求用户进行授权才能缓存超过特定大小的数据。| |Debug Symbols||启用此选项可在发生错误时保留调试符号并执行堆栈跟踪的恢复(显示原始函数名称)。对于发布版本,所有调试信息都存储在单独的文件中;发生错误时将根据需要从服务器下载该文件。开发版本始终具有嵌入在主模块中的恢复支持,因此不受此选项的影响。| |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.| |Initial Memory Size|| The initial size of the WASM heap memory in megabytes (MB). By default, this is set to 32 MB. If Memory Growth Mode is set to None, then this is also the maximum size of WASM heap memory.| |Memory Growth Mode||Choose the growth mode for the WASM heap memory from the following options. The recommended option is Geometric.| ||
None|The WASM heap memory has a fixed size configured in Initial Memory Size.| ||Linear|The WASM heap memory increases by a fixed amount configured by Linear Memory Growth Step.| ||Geometric_
The WASM heap memory increases relative to the current heap size depending on the factor configured in Geometric Memory Growth Step and Geometric Memory Growth Cap.
Maximum Memory Size The maximum size of the WASM heap memory in MB. By default, this is set to 2048 MB. This option is only available for the Memory Growth Mode Linear or Geometric.
Linear Memory Growth Step Advanced tuning option to control the WASM heap growth step in MB. By default, this is set to 16 MB. A growth step of 16MB indicates that the heap is increased by 16MB each time it needs to grow. Only available if Memory Growth Mode is set to Linear.
Geometric Memory Growth Step Advanced tuning option to control the WASM heap growth factor relative to the current heap size. By default, this is set to 0.2. A growth factor of 0.2 means that the size of the heap is increased by 0.2 * currentHeapSize each time the heap needs to grow. Only available if Memory Growth Mode is set to Geometric.
Geometric Memory Growth Cap Advanced tuning option to control the upper limit for a heap growth step in MB. By default, this is set to 96 MB. A growth cap of 96MB means that the size of the heap is increased by at most 96 MB. Only available if Memory Growth Mode is set to Geometric.

  • WASM memory options were added in Unity 2022.1.
Getting started with WebGL development
Texture Compression in WebGL
Copyright © 2020 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。