Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Why doesn't this Addressables.release() work?

Discussion in 'Addressables' started by lejean, Sep 12, 2020.

  1. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    299
    I get the error
    Addressables.Release was called on an object that Addressables was not previously aware of.  Thus nothing is being released

    What's wrong with this code. It gets loaded on start, so why can't I release it when it gets destroyed?

    Code (CSharp):
    1.  
    2. GameObject UltimateParticle;
    3. public AssetReference UltimateRef;
    4.  
    5. public void Start() {
    6.       LoadParticle();
    7. }
    8.  
    9. public void LoadParticle() {
    10.     UltimateRef.LoadAssetAsync<GameObject>().Completed += OnUltLoaded => {
    11.                 UltimateParticle = OnUltLoaded.Result;
    12.                 print("particle loaded");
    13.     };
    14. }
    15.  
    16. private void OnDestroy() {
    17.      Addressables.Release(UltimateRef);
    18. }
    19.  
     
  2. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    299
  3. stgs73

    stgs73

    Joined:
    Mar 23, 2015
    Posts:
    56
    "In all cases, however, the release method can either take the loaded asset, or an operation handle returned by the load"

    I found the loaded asset route did not work for whatever reason. Note: i am not using AssetReferences.
    I store the AsyncOp handle and use that to release. Verified it via the Addressables Event analyzer.

    Also check on diff version of Addressables, 1.13 seems the most stable but there are bugs, i could use it with 1.15 ok but there are other issues with that version

    hth
     
  4. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    467
    Use UltimateRef.ReleaseAsset instead
     
  5. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    299
    K so in my scenario it's the instantiated object you have to release not the addressable.

    So it becomes

    Code (CSharp):
    1. private void OnDestroy() {
    2.      Addressables.ReleaseInstance(UltimateParticle);
    3. }
     
unityunity