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
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

[Request] AsyncOperationHandle AssetReference.LoadAssets (IEnumerable<AssetReference> References)

Discussion in 'Addressables' started by TextusGames, Aug 12, 2019.

  1. TextusGames


    Dec 8, 2016
    This function should act like AssetReference.LoadAssetSync(). It should assign Asset variable of AssetReference.

    Preferable as an extension method with the ability to write something like this
    Code (CSharp):
    1. public List <AssetReference>  References;
    2. private AsyncOperationHandle operation;
    4. void  Start()
    5. {
    6.      operation = References.LoadAssets();
    7.      operation.Comleted += DoSomethingOnComplete;
    8. }
    10. void Update()
    11. {
    12.     if (operation.IsDone)
    13.         return;
    15.     Debug.Log( "Loaded" + operation.CompletionPercent)
    17. }
    You have provided a basic sample project called "ListOfReferences" there you just iterate for each asset reference and load it and on completion decrement some index in order to know then all assets are loaded.
    This approach assigns Asset field of each AssetReference.
    But this approach does not provide AsyncOperationHandle benefits.

    The second approach is to call operation = Addressables.LoadAssets( References.Select(r => r.RuntimeKey), SomeAction, MergeMode.Union); . Here you get the
    AsyncOperationHandle with it benefits.
    but this does not assigns Asset field of each AssetReference becouse it has not called AssetReference.LoasdResourceAsync().
    And there is no way to know which asset reference corresponds to which loaded object( because Addressables.LoadAssetsAsync() returns only unique assets and if multiple asset references have the same runtime keys the size of initial AssetReferences and the size of the returned list of objects will not be equal).

    So it would be convenient to have some built-in method to load a collection of AssetRferences with both benefits.