Search Unity

[0.7.4] How to find asset key in AsyncOperationHandle

Discussion in 'Addressables' started by whowh, Apr 24, 2019.

  1. whowh

    whowh

    Joined:
    Mar 7, 2019
    Posts:
    23
    Hi.

    In my project,
    I will save some data by using asset key when addressable load asset completed.
    But in the newest version the key in no longer in AsyncOperationHandle struct.
    Does someone have another way to find the assets key when load asset completed.

    Thanks
     
  2. TobiasW

    TobiasW

    Joined:
    Jun 18, 2011
    Posts:
    91
    I also hope that's gonna be brought back, but until then I'm gonna do this:

    Code (CSharp):
    1. reference.LoadAsset().Completed += operation => OnLoadAssetCompleted(operation, reference.RuntimeKey);
     
  3. whowh

    whowh

    Joined:
    Mar 7, 2019
    Posts:
    23
    Thanks for the reply.
    But I use the Addressables.LoadAsset<Texture>(key).
    How to use the way you post to load asset?
     
    Last edited: Apr 25, 2019
  4. TobiasW

    TobiasW

    Joined:
    Jun 18, 2011
    Posts:
    91
    Code (CSharp):
    1. Addressables.LoadAsset<Texture>(key).Completed += operation => OnLoadAssetCompleted(operation, key);
     
    unity_bill likes this.
  5. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    is it possible to get all keys from a returned AsyncOperationHandle<IList<TObject>> ?

    eg:
    var fetchedAssets = Addressables.LoadAssetsAsync<TObject>("Label", null);
    how can get the Key for each TObject in the List ?
     
  6. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    @Opeth001, I don't think there's a way to get keys of assets loaded by label. However, in another thread with @unity_bill, location will contain a PrimaryKey property (the address) in future release. Then it possible to load locations by label first, then load asset by location one by one.

    Anyway I hope the system design in general will have a more straight way to get the asset key or label after LoadAsset(s), which is convenience in async semantic.
     
    Opeth001 likes this.
  7. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    i ended up by implementing my own methode returning assets keys ^_^
    i created an Addressable Extension Editor Tool to help me Generate thousands Addresables from Assets automatically and this tool can also be used at runtime for functions like returning Addressables IDs. so for the moment im using it as a workaround until they officially support this feature.
     
    lclemens and (deleted member) like this.