admin 管理员组文章数量: 1086019
I've got a problem on my web application when I am changing the current page after downloading and running a Unity WebGL
game.
In fact, I know for sure that the game is running because I continuously hear the sounds when my player is dying.
Is there a way to delete all of the context when changing a web page? Could this be a kind of memory leak?
Edit 1: My web application is done with AngularJS / Material
I've got a problem on my web application when I am changing the current page after downloading and running a Unity WebGL
game.
In fact, I know for sure that the game is running because I continuously hear the sounds when my player is dying.
Is there a way to delete all of the context when changing a web page? Could this be a kind of memory leak?
Edit 1: My web application is done with AngularJS / Material
Share Improve this question edited Apr 20, 2016 at 10:09 MadJlzz asked Apr 20, 2016 at 9:10 MadJlzzMadJlzz 8862 gold badges18 silver badges36 bronze badges 6- This is Unity bug for sure. However, you can create a browser script to force unload everything that's loaded. – Nika Kasradze Commented Apr 20, 2016 at 9:55
- The thing is that I don't really know what is loaded by Unity. How do I manage to do that without unloading my own scripts ? – MadJlzz Commented Apr 20, 2016 at 10:01
-
1
There are like 5-10 files generated by Unity, unload them all (YourBuildName.data, YourBuildName.html.mem, YourBuildName.js, etc.) Edit: I think the are in
Release
orDebug
folder depending on a build – Nika Kasradze Commented Apr 20, 2016 at 10:13 - What do you mean by unloading them ? In the index.html file I clearly see that a unity script is loading the files but I am not having any access to tell Unity to unload this files. – MadJlzz Commented Apr 20, 2016 at 10:33
- @NikaKasradze: javascript doesn't have any direct way to remove non trivial resources. When something is loaded it usually stays that way. – Krzysztof Bociurko Commented Apr 21, 2016 at 9:06
2 Answers
Reset to default 4The solution is simple: load the WebGL unity in an iframe
, this sandboxes the application.
When you're done with the unity app just remove the node of the iframe
like:
var iframe=...;
iframe.parentNode.removeChild(iframe);
And it and all of it's resources should be instantly unloaded.
You can't municate with the Unity player directly when you're in an iframe but you still can pass messages to and from it with postMessage
.
Unity 2019.1 provided proper way to Quit the webgl and release the memory(although it has failed in my testing, maybe i am wrong, please let me know it really works or not) :
- C#: call Application.Quit()
- JS: call unityInstance.Quit(callback)
You can use JS version like this
unityInstance.Quit(function() {
console.log("done!");
});
For more please check Quit and memory cleanup
本文标签: javascriptHow do I clean up and unload a Unity WebGL canvas when changing pageStack Overflow
版权声明:本文标题:javascript - How do I clean up and unload a Unity WebGL canvas when changing page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743993540a2515169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论