Search Unity

[Feature Request] Loading gameobjects from an addressable folder

Discussion in 'Addressables' started by MaskedMouse, Feb 14, 2019.

  1. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    389
    I've put one of the folders into the addressable group which included all assets inside that folder automagically. Though when I have a script with a public AssetReference and have it reference the folder. But it cannot load the gameobjects that are in that folder.
    whereas if I give the folder a label and load it via the Addressables.LoadAssets<GameObject>(label) then it will load the prefabs into a list.

    So loading via label works but a serialized asset reference to the folder does not?
    Does someone know a workaround for this?

    But yeah feature request, would be nice to be able to reference folders as AssetReference.
     
    ModLunar and MNNoxMortem like this.
  2. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    397
    upload_2019-2-21_16-27-2.png
    The folder "Assets/AddressableAssets/Prefabs" is part of the group Prefabs with the label "Prefabs".

    Addressables.LoadAssets<GameObject>("Prefabs",null);
    • Works as long as the label is used
    Addressables.LoadAssets<GameObject>("Assets/AddressableAssets/Prefabs",null);
    • Fails with InvalidKeyException
    The folder "Assets/AddressableAssets/Prefabs" is part of the group Prefabs with the label "Prefabs".

    upload_2019-2-21_16-26-44.png
    Code (CSharp):
    1. InvalidKeyException: Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=Assets/AddressableAssets/Prefabs
    I think it is pretty obvious that the only reason the label works is because every specific item has the label when applied to the folder. However, it would be very nice to achieve the same behaviour for folders, especially when one wants to load everything beneath a subfolder - especially since the AAS properly updates all subfolder keys when the a parent folder name is changed.
     
    ModLunar likes this.
  3. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    389
    Again trying this in the future with v1.2.4 in the hope the feature has been added.
    I'm using a public AssetReference which is serialized with an addressable folder.
    In script I use:
    await Addressables.LoadAssetsAsync<SomeScriptableObject>(FolderReference, null).Task;
    But it still throws an InvalidKeyException.

    Even tried loading the resource locations from the folder using the reference doesn't work.
    Addressables.LoadResourceLocationsAsync(FolderReference, typeof(MyScriptableObjectType));
    loads 0 items.
    @unity_bill Will this be available at some point in the future or will we have to continue to use Labels?
     
    Last edited: Oct 2, 2019
  4. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    954
    Well, this isn't something we had on the list, but I don't see a huge issue with it. The main thing it'll do is bloat the catalog. Perhaps it could be an option. I'll add a ticket to explore this. For now, use labels, but we'll look into better options.
     
  5. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    389
    The main reason to use a folder is to collect all assets in there without having to constantly add them manually yourself.
    For instance a folder full of addressable scriptable objects that represent items.
    Loading all items into an array would be simply done by using an asset reference to the folder instead of a label that can change or be mistyped. An asset reference stays a reference until it is removed from addressables.

    how does it bloat the catalog?
     
  6. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    954
    first, to be clear, the way that this would work under the hood would be at build time to automatically generate a label that was the address of the folder, and assign all things in that folder with that label. Then you could do Load("folder_address") and get all the contents.
    In the catalog, that would just mean another label per addressable folder. Depending on your project, that might be a few extras, that might be hundreds.
     
  7. hanniiel

    hanniiel

    Joined:
    Jun 14, 2013
    Posts:
    37
    Going to share my workaround for this kind of situation.

    I wanted to just drop the folder but it failed, so I created groups for an specific category. i.e.
    ->Models
    and this group contains sub-categories(Folders) (I use labels for this).
    Let's say you want do add 2 types of models animals and avatar so we are going to use 2 labels for this kind of task (generalcategory,subcategory) so for each folder we have (models,animals) & (models,avatars).

    So, whenever you load those keys(categories)(folder) all assets inside this folder are loaded , if you want to load an specific asset then include the name of your asset.

    Hope it helps.
    Image attached below.
     

    Attached Files:

    unity_bill and faolad like this.