Search Unity

List of AssetReferences Asset Addresses by Group Label

Discussion in 'Addressables' started by MadMojo, Dec 15, 2020.

  1. MadMojo


    Oct 16, 2014
    If I have a list I want to fill with asset references addresses ("List<AssetReference> someGroupOfAssetsCalledCards;", just an example) and I want to populate this list of references based on the group label used to setup the addressable assets in the do I do that in script with C#? I haven't seen any connection process for getting them linked between the Asset Manager -> Addressables -> Groups -> Addressables Groups window with the assets prepared and the reference list in my script.

    My hope is I can use something simple like: someGroupOfAssetsCalledCards = FindAssetReferencesAddressesByGroupLabel("Cards"); and it just fills up the list of AssetReferences addresses from the Addressables Groups by the Group Label.

    I do not want to load or instantiate these assets. I have separate loading and loading + instantiate methods. I just want to populate the address reference list so that I can see how many asset references are in that group, and load from that list at some later point by index, and I'm not seeing how to do that anywhere.

    How do I make that connection to use the List of AssetReferences addresses for later loading? What am I missing there?

    Is the only option manually adding every single asset to the list in editor, and updating every single change manually? It feels like this should be a simple thing to do, but I don’t see any examples of how to get these asset reference addresses in C#. Very frustrated here. I thought the point of addressables is not having to load everything up, yet every example I see only shows loading an asset up by reference, and dragging and dropping every single darn asset I want to work with. That’s pretty tedious.
    Last edited: Dec 16, 2020
    Tony_Max likes this.
  2. prinoldmj


    Feb 10, 2017
    @MadMojo I am looking exactly the same things. I saw this suggestion on however these load IResourceLocation and like you i need to load the actual AssetReference types. There is nothing in the documentation for this. This seems like a really basic feature and exactly the reason you would create labels in the first place.

    Okay so we dont actually need to use AssetReference using the code from the link above we can get a list of all IResourceLocations for a particulare label. Once we have this we can loop through the IResourceLocations and simply call

    Code (CSharp):
    1. foreach(IResourceLocation loc in locations)
    2. {
    3. // If we want the handle
    4.     AsyncOperationHandle handle = Addressables.LoadAssetAsync<T>(loc);
    5. // any other method i.e. InstantiateAsync
    6. }
    A couple of tutorial videos explain this nicely

    Last edited: Dec 17, 2020
    MadMojo likes this.
  3. MadMojo


    Oct 16, 2014
    @prinoldmj Thank you for the information! I appreciate it.