Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

How do I determine if an AssetReference is currently loaded?

Discussion in 'Addressables' started by Silly_Rollo, Nov 18, 2019.

Thread Status:
Not open for further replies.
  1. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    499
    If you are trying to determine if a ScriptableObject accessed via AssetReference is loaded or not I can't see a clear method.
     
  2. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    499
    Any ideas? I get warning spam in the log about unloading an unloaded asset since I can't tell if its already unloaded or not.
     
  3. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    234
    any info on this?
     
  4. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    132
    cache the AsyncOperationHandle.

    Code (CSharp):
    1. public AssetRefereceT<Texture2D> someAssetRef;
    2. private AsyncOperationHandle<Texture2D> someHandle;
    3.  
    4. private void OnEnable(){
    5.    someHandle = someAssetRef.LoadAssetAsync();
    6. }
    7.  
    8. private void OnDisable(){
    9.   Addressable.Release(someHandle);
    10.   someHandle = default;
    11. }
    12.  
    13. private void Update(){
    14.  
    15.    var isLoaded = someHandle.IsValid() && someHandle.IsDone;
    16.    if(!isLoaded) return;
    17.    var texture = someHandle.Result;
    18.    //do somthing....
    19.  
    20. }
     
  5. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    234
    cool thanks
    i think then it could be done using the asset reference directly since they hace the public extensions of IsValid and IsDone
     
  6. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,698
    Please avoid necroposting. Instead, it's always best practice to create a new thread. I'm going to lock this thread. Please create a new one if you wish to discuss this.
     
Thread Status:
Not open for further replies.
unityunity