How to Unload unity WebGL

浪子不回头ぞ 提交于 2020-12-26 18:53:45

问题


I am using unity webGL build and this is the way to initalize/load unity webgl in javascript.

 var gameInstance = UnityLoader.instantiate("gameContainer", "Build/WebGLDemo.json", {onProgress: UnityProgress});

but there is no way to unload the webgl. I can remove the canvas tag but the problem is that some resources are remains in the memory which are not garbage collected. additionally when i try to remove

function DeleteGame(){
            console.log("remove game");
            document.getElementById("gameContainer").remove();
            //gameInstance = null;
      }

then we are getting furstum error

Screen position out of view frustum (screen pos 0.000000, 0.000000, 0.000000) (Camera rect 0 0 0 0)

Is there any proper way available to unload the webgl?


回答1:


In Unity 2019 beta, unity provides a built-in method(C#/JavaScript) to unload Unity WebGL and cleanup memory.

  • C#: call Application.Quit()
  • JS: call unityInstance.Quit(callback)

You can either use C# version or Javascript:

unityInstance.Quit(function() {
    console.log("done!");
});
unityInstance = null;

For more details check unity Forums and unity bug.

I have used this function in unity 2019.1.0 beta but i am not sure that its cleaup the memory but it definitely close unit webgl application.



来源:https://stackoverflow.com/questions/54924565/how-to-unload-unity-webgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!