Search Unity

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:
    501
    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:
    501
    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:
    345
    any info on this?
     
  4. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    148
    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:
    345
    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,820
    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.