Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Feature Request: GetAddresses(string label) and/or GetAddress(UnityEngine.Object o)

Discussion in 'Addressables' started by AlkisFortuneFish, Sep 27, 2018.

  1. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    441
    I cannot currently find any way to request all addresses for a label or find a way to find the address of something loaded via the addressables system.

    The use-case is the following:

    Want to present the user with a list of assets to pick from, profile icons for example.
    I should be able to mark them all with a label.
    I should be able to retrieve their addresses using that label to be able to load them, present them, store the selected address and unload them.
    Failing that, I should be able to load all the assets through the existing LoadAssets(string label) API, have the user select one, get and store its address and unload them.

    The former is more flexible, as the developer gets to pick whether to actually load all the assets at the same time or load them and unload them on demand.
     
    taptpci likes this.
  2. Elhimp

    Elhimp

    Joined:
    Jan 6, 2013
    Posts:
    10
    Well, right now you could work around by grouping your assets with kinda same address. Yet (maybe I'm just not looking good enough) there is no such thing as Addressables.Keys collection, which would be also nice to have, 'cause Addressables basically key-value storage thing.

    So my way to dealing with almost same task is
    Code (CSharp):
    1. IEnumerable<string> profileIconKeys = Addressables.ResourceLocators
    2.     .OfType<ResourceLocationMap>()
    3.     .SelectMany(locationMap => locationMap.Locations.Keys.Select(key => key.ToString()))
    4.     .Where(keyString => keyString.StartsWith("profileIcons/"));
     
    Last edited: Sep 28, 2018
  3. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    441
    Thanks for the snippet, I'll see if it fits the particular use case we have! :)
    I will look into implementing the actual API myself when I have the time, it's just ideally this is something the system should have from the get go, rather than something to manually implement.

    PS: Use OfType<ResourceLocationMap>(), saves you having to .Where().Cast(). :)
     
  4. Elhimp

    Elhimp

    Joined:
    Jan 6, 2013
    Posts:
    10
    Edited for future generations...
    And ofcourse idea is keyString should StartsWith something, not fully equals it.
     
  5. dri_richard

    dri_richard

    Joined:
    Mar 10, 2017
    Posts:
    35
    This is a surprising omission, given that addressables is all about orthogonality & separation of concerns.
    In our case, some of our assets will be local and others will be remote. I really don't want to load them all!
     
  6. Dunk86

    Dunk86

    Joined:
    May 10, 2015
    Posts:
    25
    Oh no...
    I just assumed that you could get a list of AssetReferences by label - what's the point if you need to completely load them all in one go?
    I thought my use case was the most obvious one:
    1) I have a list of hats, all addressables and labelled as "Hat".
    2) I query to know which hats I have, I present a menu to scroll through the hats one at a time.
    3) I load each hat prefab when I switch to it, caching it for later use.

    For a system like this to be flexible, you need to be able to query the list of addresses without loading the whole set...
    I've only just started with addressables, so maybe I'm just missing something. :/

    EDIT: I managed to workaround the issue by having a ScriptableObject that holds the list of AssetReferences that I'd want to fetch/load at runtime. Not much fun to have to do this manually, but at least I can attach useful meta-data to each element that I can use before the full load.
     
    Last edited: Feb 19, 2019 at 5:21 PM