Addressables releasing Sprite problem

Hi,

AsyncOperationHandle<Sprite> handle = Addressables.LoadAssetAsync<Sprite>(path);
if(!handle.IsDone)
            yield return handle;

        if (handle.Status == AsyncOperationStatus.Succeeded) {               
           Sprite s = handle.Result ;
           myImage.sprite = s ;
           Addressables.Release(handle);
        }

unity 2020.3.4 LTS and current stable version of Addressables is 1.16.19
In editor mode there is no problem but in Android buid, if I release the handle, Sprite is also disappear.
When I check Addressables tutorials, they are generally release the handled variable after assigning.
Why is editor and android have different results.

Thanks

I’ll flag with the team for some insight and guidance.

Hi,

Could you point me to this?
Handles should be kept and only released after the lifetime of the Asset you have loaded.

This is likely not so much that it is different in the Editor. But with the playmode script being used. If you are set to using “Use Existing Build”. Then the actual AssetBundles that are built are loaded, like they would be in the Release/Android.
With this mode, anything that is loaded, will be unloaded when all reference counts (Release calls) have been sent.
You are likely seeing this not happen with the other playmodes because they do not use the AssetBundles directly. The Assets are loaded from the AssetDatabase in the Editor are not unloaded in the same way. In general, always release handles once you no longer need the Asset, and use “Use existing build” where you want exact behaviour, with “use Asset Database” for development and iteration times.

Same here. When I load asset with this script:

public void SetDialogueBG(string[] par)
    {
        string bg = par[0];
        if (bg == "" || bg == "null")dialBG.enabled = false;
        else StartCoroutine(SetDialogueBGAsync(bg));
    }

    private IEnumerator SetDialogueBGAsync(string bg)
    {
        string addr = $"Assets/Addressables/bg/{bg}.png";
        var handle = Addressables.LoadAssetAsync<Sprite>(addr);
        yield return handle;
        if (handle.Status == AsyncOperationStatus.Succeeded)
        {
            dialBG.sprite = handle.Result;
            dialBG.enabled = true;
            Addressables.Release(handle);
        }
        else Debug.Log("SetDialogueBGAsync ERROR: " + addr);
    }

In the editor everything is fine, but in the windows build the sprite is absent.
Unity 2020.3.6.f1 LTS
Addressables Version 1.16.19 - April 15, 2021

But if I comment “//Addressables.Release(handle);” it works.

This is expected. You should not Release Assets until you no longer need them.
Something like the following:

AsyncOperationHandle<Sprite> m_Handle;

public void SetDialogueBG(string[] par)
    {
        string bg = par[0];
        if (bg == "" || bg == "null")dialBG.enabled = false;
        else StartCoroutine(SetDialogueBGAsync(bg));
    }
    private IEnumerator SetDialogueBGAsync(string bg)
    {
        string addr = $"Assets/Addressables/bg/{bg}.png";
        m_Handle = Addressables.LoadAssetAsync<Sprite>(addr);
        yield return handle;
        if (handle.Status == AsyncOperationStatus.Succeeded)
        {
            dialBG.sprite = handle.Result;
            dialBG.enabled = true;
        }
        else Debug.Log("SetDialogueBGAsync ERROR: " + addr);
    }

void IAmDoneWithMySpriteNow()
{
    // finished using the Sprite, I now want it to be unloaded.
    Addressables.Release(m_Handle);
}