Search Unity

Unity doesn't load again assets that were unloaded.

Discussion in 'Windows' started by BugKiller, Mar 3, 2015.

  1. BugKiller

    BugKiller

    Joined:
    May 8, 2014
    Posts:
    23
    Hi,

    I'm having problems re-loading assets on WP (Working good for iOS/Android).

    When I leave the Menu.scene and load the Game.scene there are some instantiates that load textures and materials to the scene. After going back to the Menu.scene I run this code to unload this assets:

    Code (CSharp):
    1.  
    2. foreach(var type in _enemiesPools.Keys)
    3. {
    4.       if(_enemiesPools[type].Count > 0 && _enemiesPools[type][0] != null)
    5.       {
    6.                 Resources.UnloadAsset(_enemiesPools[type][0].renderer.sharedMaterial.mainTexture);
    7.                 foreach(var mat in _enemiesPools[type][0].GetComponent<tk2dSprite>().Collection.materials)
    8.                 {
    9.                     Resources.UnloadAsset(mat);
    10.                 }
    11.        }
    12. }
    13.  
    When I open another level and load again the Game.scene, Unity recognizes in iOS/Android that this assets were unloaded so it loads them again and everything works fine, but in Windows Phone it doesn't load anything again (maybe because "it doesn't know" that the assets were unloaded to release memory).

    Do you know why this happens and how can I fix this?

    Thanks.
     
  2. jonestictoc

    jonestictoc

    Joined:
    Jun 24, 2013
    Posts:
    7
    We had a similar issue on Windows Phone 8.1. We fixed it by adding a empty loading scene between our Game and Menu scenes. All the loading scene did was wait 2 frames, then call Resources.UnloadUnusedAssets(), then wait 2 frames and go to the next scene. It might work for you as well.