Search Unity

Question How can I load all Addressables below a certain path/of a type/in a group?

Discussion in 'Addressables' started by kork, Jun 18, 2020.

  1. kork

    kork

    Joined:
    Jul 14, 2009
    Posts:
    280
    I'm currently trying to get familiar with the Addressables system. I have several items that are of different type and should be addressable.

    • Stories
    • Wearables
    • Stackable Items
    • Enemy types
    Now I would like to load these by their path (e.g. all stories are in a folder named "Stories", so I'd like to load all Addressables which have a path starting with "Stories/*").

    Code (CSharp):
    1.            
    2. // use the path with a wildcard as key name
    3. Addressables.LoadAssetsAsync<StoryDescriptor>("Stories/*", null);
    4.  
    Didn't work. Next I tried if I could load all of them by type and without specifying a key at all:

    Code (CSharp):
    1.            
    2. // use no key name at all , just a type
    3. Addressables.LoadAssetsAsync<StoryDescriptor>(null, null);
    4.  
    Didn't work either. So next I tried to put them into groups also because the documentation said it's a good idea to split your stuff up and I figured maybe one could load stuff with the group name:

    • Group: Stories
      • Story 1
      • Story 2
    • Group: Wearables
      • Armor 1
      • Weapon 1
    • Group: Stackables
      • Food
      • Components
    • etc..
    I tried with this code:

    Code (CSharp):
    1.            
    2. // use the group name as key
    3. Addressables.LoadAssetsAsync<StoryDescriptor>("Stories", null);
    4.  
    Didn't work either. But I found there is a thing called labels and it would seem one could load stuff by label. So I tried, sticking a label to each of the Addressables:

    • Group: Stories
      • Story 1
        • Label: Story
      • Story 2
        • Label: Story
    • Group: Wearables
      • Armor 1
        • Label: Wearable
    • etc..

    Now I was able to load Addressables by label like this:

    Code (CSharp):
    1.            
    2. // use the label name as key
    3. Addressables.LoadAssetsAsync<StoryDescriptor>("Story", null);
    4.  
    But this is a really error prone way of organizing things. I need to remember to put stuff into the right group and also add a label to it. Is there a way I can load addressables that match a certain path in their keys or just all Addressables of a certain type?
     
    AldeRoberge, wlwl2 and saferusmail like this.
  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    That is actually a really useful feature request.

    For now, though, I think you can implement a script that will attach labels for your needs.