Replace deprecated browser interaction code
Replace any deprecated code with the updated code.
Read time 3 minutesLast updated 3 days ago
Make the updates required to maintain compatibility with Unity Web builds.
Updates include replacing deprecated or removed browser scripting code and recompiling native C/C++ plug-ins 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 or removed and you need to replace it with the replacement code.
Deprecated code | Replacement code |
|---|---|
| dynCall() | |
| Pointer_stringify() | |
| unity.Instance() | |
| gameInstance | |
| MEMORY_FILENAME and WORKER_FILENAME | Remove references |
| stackTrace() | |
Change dynCall to makeDynCall
The function isn't available in Unity Web builds, because Unity Web builds always target WebAssembly 2023, which uses the language feature. This also applies to the and functions. If you have any code that uses , replace it with .
dynCallWebAssembly.TabledynCall_*()Module.dynCall()dynCallmakeDynCallFor example, change:
dynCall('vii', callback, [1, 2])
to:
{{{ makeDynCall('vii', 'callback') }}}(1, 2)
Calling a function with no arguments
When migrating a that has no arguments, you must add empty parentheses () after the template to invoke the function.
dynCallmakeDynCallFor example, change:`
dynCall('v', callback, []);
to:
{{{ makeDynCall('v', 'callback') }}}()
Change Pointer_stringify() to UTF8ToString
The function is deprecated. If your code contains calls to , replace the calls with .
Pointer_stringify()Pointer_stringify()UTF8ToString()For example, change:
var stringMessage = Pointer_stringify(message);
to:
var stringMessage = UTF8ToString(message);
Change unity.Instance to CreateUnityInstance
unity.Instanceunity.InstanceCreateUnityInstanceFor 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 property is deprecated. If your code uses , use instead.
gameInstancegameInstanceunityInstanceFor example, change:
MyGameInstance = gameInstance;
to:
MyGameInstance = unityInstance;
Remove references to MEMORY_FILENAME and WORKER_FILENAME
The preprocessing macros and 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.
MEMORY_FILENAMEWORKER_FILENAMEChange stackTrace() to new Error().stack.toString()
The global function is deprecated. Replace instances of with instead.
stackTrace()stackTrace()new Error().stack.toString()Update native C/C++ plug-ins for WebAssembly 2023
Unity Web builds always target WebAssembly 2023 and rely on an updated Emscripten toolchain. If your project uses native C/C++ plug-ins that were compiled without WebAssembly 2023 support, you need to recompile them 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-ins to ensure they're compatible for all users building projects for the Web platform.