【Unity2020 WebGL无法加载异常】 Uncaught ReferenceError: unityFramework is not defined at HTMLScriptElement

问题

Unity2020 打包出WebGL,打开项目会卡在读条界面,无法进入场景。

控制台报错UncaughtReferenceError: unityFramework is not defined at HTMLScriptElement
与Uncaught SyntaxError: Invalid or unexpected token。

这是因为:

从 Unity 2020.1 开始,Unity WebGL 项目默认不再启用 gzip 和 brotli 的软件解压缩回退
在2020之前,是使用一套通用的WebGL打包模板,不会区分设置中使用了gzip、brotli或未使用压缩。默认把gzip和brotli的解压缩回退都写入,这样造成了空间浪费。

解决办法:

1.不使用压缩。修改打包设置PlayerSettings中Plublishing Settings的压缩格式Compression Format为Disabled。但打包后体积会变大。

2.使用解压缩回退。还是将压缩格式设置为Gzip或Brotli,并勾选打包设置PlayerSettings中Plublishing Settings的Decompression Fallback。

新的问题

打包成功,可能会出现新的问题:both async and sync fetching of the wasm 。而无法加载。

可以参考我这篇博客来解决问题。

参考:https://forum.unity.com/threads/changes-to-the-webgl-loader-and-templates-introduced-in-unity-2020-1.817698/

你可能感兴趣的:(Unity,UnityWebGl,unity,unity3d,webgl)