Unload all assets in the old scene when changing the scene

Hey guys, I was using the default changing scenes script from the tuturial Loading Scenes | Learn PlayCanvas ,

However I found the VRAM are keep increasing when I change scenes for multiple times, it doesn’t hurt when I am using my computer, however when I run games on my iphone, changing scenes could cause Safari kill the tab due to high memory allocation.

So, I want to know how to unload all assets in the old scene when I am changing the scenes, I know assets.unload() could clear all VRAMs, but how could I get all assests in the scene?

Thanks in advance! This will help me a lot!

You will have to manage the assets yourself in a way that’s similar to what is suggested at the bottom of the page: https://developer.playcanvas.com/en/user-manual/packs/loading-scenes/#managing-assets-in-scenes

But instead of loading, you would unload. So the steps would be similar to:

  1. preload the next scene data
  2. destroy all the Entities in the app
  3. Optional: show a loading screen
  4. unload unneeded assets
  5. load next scene assets
  6. add next scene to app

Or some sort of variation of the above

1 Like