Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unloading Sprite Atlas using Addressables

Discussion in 'Addressables' started by JC_Andres, Jun 19, 2019.

  1. JC_Andres

    JC_Andres

    Joined:
    Jan 23, 2019
    Posts:
    3
    Hello, I'm in the process of moving our project assets to sprite atlases and use addressables to load them up. This is working correctly by using the SpriteAtlasManager callbacks to handling loading.

    Code (CSharp):
    1. public void StartHandlingSpriteAtlases()
    2.     {
    3.         SpriteAtlasManager.atlasRequested += SpriteAtlasManagerOnAtlasRequested;
    4.         SpriteAtlasManager.atlasRegistered += SpriteAtlasManagerOnAtlasRegistered;
    5.     }
    6.  
    7.     public void StoptHandlingSpriteAtlases()
    8.     {
    9.         SpriteAtlasManager.atlasRequested -= SpriteAtlasManagerOnAtlasRequested;
    10.         SpriteAtlasManager.atlasRegistered -= SpriteAtlasManagerOnAtlasRegistered;
    11.     }
    12.    
    13.     private void SpriteAtlasManagerOnAtlasRegistered(SpriteAtlas spriteAtlas)
    14.     {
    15.         Assert.IsNotNull(spriteAtlas, "Found null sprite Atlas!");
    16.         Debugger.LogInfo($"Registered Sprite Atlas {spriteAtlas.name}");
    17.     }
    18.  
    19.     private void SpriteAtlasManagerOnAtlasRequested(string atlasId, Action<SpriteAtlas> callback)
    20.     {
    21.         LoadAtlasFromAddressables(atlasId, callback);
    22.     }
    23.  
    24.     private async void LoadAtlasFromAddressables(string atlasId, Action<SpriteAtlas> callback)
    25.     {
    26.         SpriteAtlas spriteAtlas = await Addressables.LoadAssetAsync<SpriteAtlas>(atlasId);
    27.         callback(spriteAtlas);
    28.     }
    My question is then, what is the suggested process to unload sprite atlases. The SpriteAtlasManager doesn't seem to provide any interface that lets me know that it is done using an atlas, and short of doing reference counting myself (which would involve tagging every place where I use a sprite) I don't see a way in which I can unload the atlases, and since I had to do the load manually I doubt Unity is handling the unloading for me.

    Any suggestions or advice is welcome.
     
    jfilion likes this.
  2. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,053
  3. AnthonyReddan

    AnthonyReddan

    Joined:
    Feb 27, 2018
    Posts:
    39
    Hi there, did you figure this out? Is it ok to just leave it loaded in memory?

    Curious how it works when "Include in Build" is checked.