Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Load assets using Label? [Resolved]

Discussion in 'Addressables' started by Opeth001, Jul 15, 2019.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,068
    Is it possible to load all addressable assets directly via label ?

    EDIT:
    i found it.

    Addressables.LoadAssetsAsync<GameObject>(MyLabelString, null).Completed += objects =>
    {
    foreach (var go in objects.Result)
    Debug.Log($"Addressable Loaded: {go.name}");
    };
     
    Last edited: Jul 15, 2019
  2. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    818
    Just found this as well, its really odd we need to pass a callback when we also get it as a result.
     
    oxysofts likes this.
  3. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    404
    Thanks, works great!
    @TJHeuvel-net isn't that because it's async? If you put Debug.Log(Time.time) inside the callback and after the callback, the inside will be called slightly after.

    Objects is an IList<GameObject> or whatever type you put in the LoadAssetsAsync call.
     
  4. emadkh

    emadkh

    Joined:
    Aug 23, 2013
    Posts:
    21
    I think this hasn't been mentioned anywhere in the documentation. the asset label name needs to have brackets. I meant the label name pattern should be as follow [labelName] otherwise it won't work.
     
    pandolfini and creepteks like this.
  5. crawfis

    crawfis

    Joined:
    Jan 30, 2014
    Posts:
    103
    @e-khezri. You do not need brackets and none of the examples use them, nor do I.
     
  6. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,511
    This does not work with getting Sprites in Sprite Sheet.

    So say :

    Addressables.LoadAssetsAsync<IList<Sprite>>("Sprite", null);

    Does not work.
     
  7. Ardito92ITA

    Ardito92ITA

    Joined:
    Apr 1, 2014
    Posts:
    37
  8. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    Awesome, thanks a lot for this. Trying to figure this stuff out with just the docs is a nightmare
     
    lclemens likes this.
  9. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    714
    Yeah... it seems like some things work and some don't. For example this will fail:

    Code (CSharp):
    1. yield return Addressables.LoadAssetsAsync<ParticleSystem>("pfx", pfx => { UnityEngine.Debug.Log("Loaded asset: " + pfx.name); });
    But this will succeed:

    Code (CSharp):
    1. yield return Addressables.LoadAssetsAsync<AudioClip>("aud", clip => { UnityEngine.Debug.Log("Loaded asset: " + clip.name); });
    The only difference between the two is that working one uses type AudioClip and the failing one uses type ParticleSystem.

    If it doesn't work, you'll get an error like this:

    Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[System.Collections.Generic.IList`1[UnityEngine.ParticleSystem]], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=pfx, Type=UnityEngine.ParticleSystem

    The only way I know of to get around it is to use a GameObject instead like:

    Code (CSharp):
    1. yield return Addressables.LoadAssetsAsync<GameObject>("pfx", go => {
    2.             ParticleSystem pfx = go.GetComponent<ParticleSystem>();
    3.             UnityEngine.Debug.Log("Loaded asset: " + pfx.name);
    4. });
    It's slightly more code, but it gets the job done.
     
  10. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    714
    Does anyone know how to get the Addressable string from the game object instead of the game-object name?

    For example in Opeth001's code go.name is not the addressable string... it is the game object's name.
     
    Eat-Food likes this.
  11. Hyndavi_Nandhigama

    Hyndavi_Nandhigama

    Joined:
    Jul 22, 2020
    Posts:
    1
    I want to load all the Assets from Addressable using lable, I want to use it for WebGL build where Multi threading is not supported, can someone help me how to load assets using single thread.
     
  12. ryancrime

    ryancrime

    Joined:
    Sep 4, 2020
    Posts:
    2
    Can I use the same method to load a scene instead of a GameObject?
     
  13. justjack1521

    justjack1521

    Joined:
    Dec 28, 2020
    Posts:
    2
    Leaving for anyone here as I was trying to figure out the same thing, the second function
    LoadAndAssociateResultWithKey on this page helped me get it working
     
    ProGameDevUser likes this.
  14. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    714
    Does anyone know how to fetch the labels associated with a particular asset from IResourceLocation or an AsyncOperationHandle?

    I'm loading a whole bunch of labels all at once via LoadResourceLocationsAsync() and it would be handy to fetch a list of labels for each one so I could organize the resulting objects into various lists.
     
  15. luistorres_emvenci

    luistorres_emvenci

    Joined:
    Aug 23, 2021
    Posts:
    16
    Hi! have you ever found a good way to use labels to properly load assets on WebGL. Recently I've run into a similar'ish problem here.