Search Unity

Why do subsequent calls to load an already loaded asset take as long as the first time?

Discussion in 'Addressables' started by wheee09, Jan 14, 2019.

  1. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Hi,

    Two questions actually:
    1. Maybe I'm missing something, but given that loading an already loaded asset should be increasing the refcount, and I'm only assuming that there's a Dictionary nested deep in there somewhere... shouldn't subsequent calls be much faster than the initial call to load an asset?

    I did a simple experiment where I called LoadAsset() twice on the same address path in Fast mode (Virtual mode doesn't work right now) and the time for the async call was essentially about the same. (edit) We're talking about 100-200ms but if I add a caching mechanism on top of Addressables, then subsequent calls to load an already loaded asset take 16ms.

    2. Maybe a dumb question, but what does it exactly mean to ReleaseAsset()?

    For example (adapted from https://docs.unity3d.com/Packages/c...4/manual/AddressableAssetsGettingStarted.html):
    Code (CSharp):
    1.  
    2.        GameObject myGameObject;
    3.  
    4.         ...
    5.         Addressables.LoadAsset<GameObject>("AssetAddress").Completed += onLoadDone;
    6.     }
    7.  
    8.     private void onLoadDone(UnityEngine.ResourceManagement.IAsyncOperation<Sprite> obj)
    9.     {
    10.             myGameObject = obj.Result;
    11.             Addressables.ReleaseAsset(obj.Result);
    12.     }
    13.  
    And later, if I try to use myGameObject (whether it's the same frame or at a later frame), I'm still able to use it.

    So does that mean given the fact that I have local variable referencing the asset, GC won't be able to reclaim it, despite "releasing" it?

    Thanks
     
    Last edited: Jan 14, 2019
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    1. don't do timing tests in FastMode. it's a completely artificial environment, loading from the AssetDatabase and in no way reflects what things will be like in real life.
    2. ReleaseAsset decrements the ref count. Once a count is at 0, the thing is eligible for unload.