Search Unity

How to UnloadAsset

Discussion in 'Scripting' started by EvandroLins, Jul 8, 2012.

  1. EvandroLins

    EvandroLins

    Joined:
    Jul 8, 2012
    Posts:
    5
    I'm having a little problem trying to unload some assets, has someone here successfully used it?
    The documentation don't say much about how to use it, and looks that it is a really unfamous method, google only showed two results.

    Code (csharp):
    1.  
    2. Object _puzzle;
    3.  
    4. _puzzle = Resources.Load("resource");
    5. Instantiate(_puzzle);
    6.  
    7. Resources.UnloadAsset(_puzzle);
    8.  
    And the error I always get is: UnloadAsset may only be used on individual assets and can not be used on GameObject's / Components or AssetBundles
    UnityEngine.Resources:UnloadAsset(Object)
     
    Last edited: Jul 8, 2012
  2. Bluntweapon

    Bluntweapon

    Joined:
    Feb 24, 2012
    Posts:
    158
    Hmm, since you didn't specify exactly what it is you loaded, Unity assumes you loaded a Prefab (hence the GameObject reference in the error), and you don't need to unload prefabs (I don't think. Someone correct me if I'm wrong here).
     
  3. Fliperamma

    Fliperamma

    Joined:
    Apr 24, 2012
    Posts:
    31
    Hello guys, I'm having the same problem here ... if somebody knows why this happens, please explain.

    Thanks
     
  4. Lisan

    Lisan

    Joined:
    Jun 17, 2009
    Posts:
    220
    Same here, please, someone, how to use it to unload prefab loaded from resources? I instantiated it directly from Resource.Load() casting it to GameObject. Should i store it as Object first, to be able to unload it later?
     
  5. Fordeka

    Fordeka

    Joined:
    Aug 18, 2011
    Posts:
    78
    It appears to only work on asset container classes- for example if I load a prefab that contains an atlas for my particular UI package and I try to unload it I will get that error but if I try to unload the Texture member of the class it works fine.