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