Version: Unity 6.6 Alpha (6000.6)
Language : English
JavaScript interface in Unity Web builds
Web native plug-ins for Emscripten

Replace deprecated browser interaction code

Make the updates required to maintain compatibility with Unity Web builds.

Updates include replacing deprecated browser scripting code and recompiling native C/C++ plug-insA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary
for use with WebAssembly 2023. Apply these changes to prevent unexpected behavior or broken code in your project.

Deprecated code

The following code is deprecated and you need to replace it with the replacement code.

Deprecated code Replacement code
dynCall() makeDynCall()
Pointer_stringify() UTF8ToString()
unity.Instance() CreateUnityInstance()
gameInstance unityInstance
MEMORY_FILENAME and WORKER_FILENAME Remove references
stackTrace() new Error().stack.toString()

Change dynCall to makeDynCall

The dynCall function is deprecated. If you have any code that uses dynCall, replace it with makeDynCall. Make this change whether you have WebAssembly.Table enabled or not. This update is required for compatibility with WebAssembly 2023.

For example, change:

dynCall('vii', callback, [1, 2])

to:

{{{ makeDynCall('vii', 'callback') }}}(1, 2)

Calling a function with no arguments

When migrating a dynCall that has no arguments, you must add empty parentheses () after the makeDynCall template to invoke the function.

For example, change:`

dynCall('v', callback, []);

to:

{{{ makeDynCall('v', 'callback') }}}()

Change Pointer_stringify() to UTF8ToString

The Pointer_stringify() function is deprecated. If your code contains calls to Pointer_stringify(), replace the calls with UTF8ToString().

For example, change:

var stringMessage = Pointer_stringify(message);

to:

var stringMessage = UTF8ToString(message);

Change unity.Instance to CreateUnityInstance

unity.Instance is deprecated. If your code uses unity.Instance, use CreateUnityInstance instead.

For example, change:

var MyGameInstance = null;
  script.onload = () => {
    unity.Instance(canvas, config, (progress) => { /*...*/ }).then((unityInstance) => {

to:

var MyGameInstance = null;
  script.onload = () => {
    createUnityInstance(canvas, config, (progress) => { /*...*/ }).then((unityInstance) => {

Change gameInstance to unityInstance

The gameInstance property is deprecated. If your code uses gameInstance, use unityInstance instead.

For example, change:

MyGameInstance = gameInstance;

to:

MyGameInstance = unityInstance;

Remove references to MEMORY_FILENAME and WORKER_FILENAME

The preprocessing macros MEMORY_FILENAME and WORKER_FILENAME are obsolete and can be removed. Web page templates in previous versions of Unity used these macros to identify additional files related to the generated build.

Change stackTrace() to new Error().stack.toString()

The global stackTrace() function is deprecated. Replace instances of stackTrace() with new Error().stack.toString() instead.

Update native C/C++ plug-ins for WebAssembly 2023

Projects built with WebAssembly 2023 rely on an updated Emscripten toolchain. If you rebuild a project with WebAssembly 2023, you need to recompile any native C/C++ plug-ins with a specific set of build flags to ensure compatibility. To recompile your plug-ins, refer to Compile native plug-ins with Emscripten.

For third-party package developers, the recommended best practice is to recompile your native plug-insA platform-specific native code library that is created outside of Unity for use in Unity. Allows you can access features like OS calls and third-party code libraries that would otherwise not be available to Unity. More info
See in Glossary
to ensure they’re compatible for all users building projects with WebAssembly 2023.

Note: You must also replace dynCall with makeDynCall to ensure compatibility with WebAssembly 2023.

Additional resources

JavaScript interface in Unity Web builds
Web native plug-ins for Emscripten
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961