When Unload (Application.Quit) is Necessary

Hi there! I have a general question related to when to manually unload Unity or call Application.Quit().

Let's say for example I have the following pages in a site:

  • Home - a non unity page to select a game

  • Game - a unity page

Do I need to handle unload for these following scenarios?

  • Game -> Home (via the browser's back button)

  • Game -> Home (via an in-game "Back to Home" button)

  • Game -> Game (via the browser's refresh button)

Or put more simply - do I need to manually unload through a page transition? Or would I only need to unload Unity manually if this site was, let's say, a single page that handled multiple unity players on the same page.

Details on my specific implementation:
- Next.JS React Site (in non-SSR mode)
- Using the react-unity-webgl helper
- Game is pretty tiny in memory

There is nothing you need to handle when another URL is opened in the same tab, or the tab is reloaded.


I'm thinking Quit() doesn't even do anything on the web. You'd have to "quit" on the JS side by removing the content iframe Unity renders to - or just plain simply load a different URL, at which point all page resources are unloaded, be it HTML, images, scripts or Unity.


Not if it's a separate page. The browser should unload all page contents itself after leaving it.


Yes. But this should be done on the website through JavaScript, not inside Unity.

Keep in mind that Application.Quit() does nothing it WebGL. Same with OnApplicationQuit.
If you'd need OnApplicationQuit for cleanup, such as disconnecting a websocket for example, you'd have to pass a browser event such as window.beforeunload through JavaScript into the Unity player instance.
The same should work the other way around, with a quit function getting passed into the browser window. You could unload the player instance manually that way then, but implementing it is totally up to you.