Search Unity

Addressables.Release

Discussion in 'Addressables' started by KB73, Sep 16, 2019.

  1. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Ignore msg, we found a soln, thnx


    Just playing around with the Addressables for the first time.

    We're trying to release our addressable via Addressables.Release
    We're on the latest 1.2.3 addressables

    Here is how we load..

    var obj = Addressables.LoadAssetsAsync<T>(assetId, (result) =>
    {
    // Release the asset here or later somewhere, key is to store off the result..
    Addressables.Release(result);
    });

    We're seeing this in the console output

    "Addressables.Release was called on an object that Addressables was not previously aware of. Thus nothing is being released"


    Is this expected?

    The callback method for us is the most simple, we don't want to use Coroutines, the async/await stuff is tricky and seems not fully ready yet? The callback handler is ok but then you have the issue of passing through extra data somehow into the CompletedCalls, just lots of extra stuff that shouldn't be needed.
    So we wanted to use lambda, but this is only on the LoadAssetsAsync not LoadAssetAsync

    Either way, if i pass in the the 'return' value ( the AsyncOpHandle - obj ) into the Release function - i don't see the error

    But the docs say i can pass in the TObject...so we are following the correct procedure as far as we can see.......is there something we're not understanding here?


    * Nevermind, we switched back to async/await, missed a few things that simplified things considerably

    many thanks
     
    Last edited: Sep 16, 2019
  2. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    In the case of LoadAssetsAsync() you actually have to Release() the var obj instead of the result.

    So you have to store a reference to that obj for as long as the asset should live until you’re ready to unload it.

    You’re right, I think, that things become a lot simpler when you use coroutines because the callbacks have no way to pass important data without creating closures.
     
    xwin28 likes this.
  3. chaseholton

    chaseholton

    Joined:
    Dec 17, 2012
    Posts:
    78
    I'm getting this same error OP, and I can't figure it out to save my life. I'm using something similar...


    I've been reading GameDev Guru's Addressables tutorial.

    This is for OnEnable, loading the objects...
    Code (CSharp):
    1.     void OnEnable()
    2.     {
    3.         if (manageMeshModel)
    4.         {
    5.             meshReference.LoadAssetAsync<Mesh>().Completed += handle => meshFilter.sharedMesh = handle.Result;
    6.         }
    7.  
    8.         if (manageMeshMaterials)
    9.         {
    10.             _materialHandle =
    11.                 Addressables.LoadAssetsAsync<Material>(_materialRuntimeKeys, null, Addressables.MergeMode.Union);
    12.             _materialHandle.Completed += handle =>
    13.             {
    14.                 handle.Result.CopyTo(_savedMaterials, 0);
    15.                 meshRenderer.sharedMaterials = _savedMaterials;
    16.             };
    17.         }
    18.     }
    Then obviously this is to unload it. It's super odd.
    Code (CSharp):
    1.     void OnDisable()
    2.     {
    3.         if (manageMeshModel)
    4.         {
    5.             var model = meshFilter.sharedMesh;
    6.             meshFilter.sharedMesh = null;
    7.             Addressables.Release(model);
    8.         }
    9.  
    10.         if (manageMeshMaterials)
    11.         {
    12.             Addressables.Release(_materialHandle);
    13.         }
    14.     }
    Same error that the addressables were previously unaware of a mesh, the material doesn't through an error but on disabled objects I have checked and the material is still on it. Addressables need more documentation! Unless I missed something official, this is all super new to me.
     
    pahe likes this.
  4. Houtamelo

    Houtamelo

    Joined:
    Jan 3, 2020
    Posts:
    31
    Necroing this thread because it frequently shows up at google searches.

    If you're receiving those warnings make sure that you are releasing the Handles themselves through Addressables.Release(put handle here), not the results.
    Also worth noticing that if you are using Addressables.InstantiateAsync(), if you want to destroy the created GameObject and release it's depedencies, use Addressables.ReleaseInstance(put handle here). Addressables.ReleaseInstance() will destroy the GameObject for you (you don't need to manually call Destroy(GameObject).
     
    Deleted User, ChiuanWei and JohngUK like this.
  5. Blitzkreig95

    Blitzkreig95

    Joined:
    Jul 21, 2021
    Posts:
    20
    Will the asset be removed from memory even if the asset bundle's other assets are still active ? How do we unload the entire asset bundle ?
     
    njellingson likes this.
  6. MH2B

    MH2B

    Joined:
    Nov 24, 2018
    Posts:
    5
    !! Solved !!
    I had the same error and I solved it. Imagine my asset Reference name was a_Ref and said a_Ref.LoadAssetAsync<T>().
    Then when I wanted to release it I was saying Addressables.Release(a_Ref) and that was why I was seeing the error.
    But now I say a_Ref.ReleaseAsset() and no errors and its working like a charm.
    And dont forget always to check if the asset is Valid before you try to release it Like this :
    if (a_Ref.IsValid()) a_Ref.ReleaseAsset();
    Hope this helps others.
     
  7. Houtamelo

    Houtamelo

    Joined:
    Jan 3, 2020
    Posts:
    31
    You would have to release every single handle you requested that belongs to the specific bundle (and destroy gameobjects with ReleaseInstance if you have any).

    Addressables will not unload the bundle from memory until it's certain that you're not using it anymore.
     
    radiantboy and Blitzkreig95 like this.
  8. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Can you please explain what you mean by handle? I am facing this error trying to release an assetReferenceGameObject. any ideas?