Author Topic: Atlas Materials not clearing on Scene change  (Read 2571 times)

Retribution

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Atlas Materials not clearing on Scene change
« on: March 02, 2017, 11:09:02 PM »
Hello,

I recently noticed that nearly every Texture or Material I'm loading into my scenes are not getting cleared as I transition to my next scene.  In the past, I circumvented these issues typically by loading to a blank or nearly empty scene while I'm loading in my next scene, but this seems to not be working in my current project.

Below is a sample of how I'm changing scenes, with some extra fluff removed for brevity.  (Note: The textures/material in question are mostly NGUI atlas materials, but I have some general Sprites that are not clearing either).

   
  1. public IEnumerator LoadLevel()
  2.     {
  3.         // Load into an empty scene
  4.         SceneManager.LoadScene("EmptySene", LoadSceneMode.Single);
  5.  
  6.         // Asychronously load in our new scene
  7.         asyncLoad = SceneManager.LoadSceneAsync("NextScene", LoadSceneMode.Additive);
  8.         asyncLoad.allowSceneActivation = false;
  9.  
  10.         // Wait until scene has finished loading
  11.         while (!asyncLoad.isDone) {
  12.             yield return new WaitForEndOfFrame();
  13.         }
  14.  
  15.         // NGUI specific call to release unused assets
  16.         UIDrawCall.ReleaseInactive();
  17.  
  18.         // Unload any unused assets here and then allow our scene to load
  19.         yield return Resources.UnloadUnusedAssets();
  20.         asyncLoad.allowSceneActivation = true;
  21.     }

Typically, I would except all loading textures and materials from the previous scene to be removed since I loaded into my "EmptyScene" in Single mode, and then unloaded any unused assets before activating my next scene.  However, I'm seeing a vast majority of my assets remain within memory while using the Profiler both during Editor testing and on iOS devices.

Granted, I used this method previously when all scene loading was done via the Application class, so perhaps this approach has changed and I'm not aware. I have a few assets in Resources, but they're not large and the assets that are sticking are not included or reference from there.  I've also been careful not to statically reference any assets to prevent them from properly clearly.

Anything else I should be looking out for?  In the Profiler, I will literally see that a single reference to the Material remains, but claims it's not being utilized by any GameObjects in the scene.  If that is the case, why does calling UnloadUnusedAssets() not clear these?

Any ideas or tips would be greatly appreciated.  Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlas Materials not clearing on Scene change
« Reply #1 on: March 06, 2017, 05:23:16 PM »
Not entirely sure about this one... NGUI doesn't tackle loading / unloading of assets. Did you try UIDrawCall.ReleaseAll() instead of ReleaseInactive()?