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

Help Wanted Correct way of loading different content

Discussion in 'Addressables' started by Nyankoooo, Oct 1, 2021.

  1. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    122
    My Addressable contains Sprites and AudioClips. Is the following way a good approach to load this?

    Code (CSharp):
    1. spritesHandle = Addressables.LoadAssetsAsync<Sprite>("MyAddressable", null);
    2. audioClipsHandle = Addressables.LoadAssetsAsync<AudioClip>("MyAddressable", null);
    3.  
    4. var loadedObjects = await UniTask.WhenAll(spritesHandle.ToUniTask(), audioClipsHandle.ToUniTask());
    I'm not sure of this code loads the Addressable two times and then takes only the requested assets, which is especially with remote assets (probably) not the best approach.
     
    Last edited: Oct 6, 2021
  2. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    122
    Does anyone know?
     
  3. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    311
    I am not sure what the null you are passing into LoadAssetAsync is, what version are you on?

    but I suppose it's fine to do it that way, if you see no errors should be fine.
     
  4. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    122
    @sniffle63 The null parameter is the callback, which I don't need because of async/await.

    The main question is not if I can do it this way, but whenever this is the best approach taking remote assets into consideration.
    It is currently not clear if above code will download the same asset twice or not, which could be an issue for mobile apps.
     
  5. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    311
    You'll have to debug to find that out on your own. If you don't understand how code is executing then don't do it that way, do it a way you understand.

    My previous question still stands tho, I do not have a second parameter on my LoadAssetAsync call and there is no overload for it, so curious what version you are on.
     
  6. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    122
    Version 1.19.6
     
unityunity