Support => NGUI 3 Support => Topic started by: Fordeka on October 11, 2012, 09:37:24 AM
Title: How to properly load and unload UIAtlases?
Post by: Fordeka on October 11, 2012, 09:37:24 AM
When I try to Resources.UnloadAsset on a UIAtlas loaded with Resources.Load I get the error, "UnloadAsset may only be used on individual assets and can not be used on GameObject's / Components or AssetBundles". If I call it on the UIAtlas's Texture it frees the memory but breaks the atlas and loading the Texture back manually doesn't work (this method does not work with the material either). Is there a method for loading/unloading UIAtlases that you know of that works?
Thanks.
Title: Re: How to properly load and unload UIAtlases?
Post by: ArenMook on October 11, 2012, 09:34:04 PM
Call it on the atlases game object, not the atlas itself.
Title: Re: How to properly load and unload UIAtlases?
Post by: Fordeka on October 12, 2012, 12:26:46 PM
I still get, "UnloadAsset may only be used on individual assets and can not be used on GameObject's / Components or AssetBundles".
Title: Re: How to properly load and unload UIAtlases?
Post by: Nicki on October 13, 2012, 06:27:19 AM
Another way to do it is
Destroy(asset); Resources.UnloadUnusedAssets();
Although that's a bit heavier to run, so don't do it mid-game, where your reactions are needed - do it in the menu at a transition or something like that.
Title: Re: How to properly load and unload UIAtlases?
Post by: Fordeka on October 14, 2012, 06:52:00 PM
When I do that, it destroys the actual UIAtlas prefab (or the UIAtlas component itself if you target that with the destroy) from the project completely. If you meant Destroy the UISprites that use the atlas I want unloaded from memory, I already tried that and then called Resources.UnloadUnusedAssets but it did not result in a release of memory.
The only way I have successfully been able to release memory used by atlases is change the scene or unload the textures used by the atlases, but that makes them unusable until I restart the game.
Title: Re: How to properly load and unload UIAtlases?
Post by: ArenMook on October 15, 2012, 06:39:46 AM
If simply calling Resources.UnloadUnusedAssets() doesn't release memory for you, then your atlas and its texture is still being used somewhere. I can't really suggest much beyond that.
Title: Re: How to properly load and unload UIAtlases?
Post by: hvilela on November 07, 2012, 02:00:21 PM
Have you found a solution to this problem? I have the same issue, how to unload an atlas loaded by "Resources.Load"?
Title: Re: How to properly load and unload UIAtlases?
Post by: nah0y on November 09, 2012, 04:20:33 AM
I think it's working for me like that :
atlasMaterial is a reference to the material of my atlas.