Search Unity

[Solved] Looking for a way to filter addressables assets at runtime.

Discussion in 'Addressables' started by Djayp, Oct 10, 2019.

  1. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    69
    Hello !

    I have a set of prefabs with a component storing two values for filter (an int and a byte). I'm looking for a way to filter them at runtime before intantiation, something like a label mask but :
    - I can't find labels from IResourceLocation
    - Create a data table to store these values along with the relative prefab key seems pretty redundant with the addressable system
    - Parsing key strings to find an int and a byte looks weird...

    I feel like I'm missing something. How would you achieve this ?
     
    Last edited: Oct 10, 2019
  2. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    146
    If you know asset key and label than you can iterate through AllResourceLocators and their keys and locate only keys that matches the label. Each label based key will contain set of resource locations of assets that have that label. You can check if there is a location with matched primary key ( name based key).
     
  3. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    146
    Or actually in first step you can just ResourceLocator.Locate("yourLabel"); to receive all locations that match label.
     
  4. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    69
    So I should Locate twice (once for each label) and extract the locations only if they are in both ? There is no way to attach data to the addressable entry and get them along with the IResourceLocation ?

    Problem is it looks like a better way to handle a custom lookup table here, and I'm not sure why or how I should use Addressables in such a case.
     
  5. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    146
    Maybe with custom build.
     
    Djayp likes this.
  6. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    69
    "NOTE: This API is going to be replaced soon with a more flexible build system."

    Haha I guess so...
     
  7. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    302
    Obviously you can not filter entries data without loading them first. Unless you can attach extra data into the system, which is not currently available. I wonder whether unity dev would like to add this feature. If you see how it implements, the system flatten all keys (address or label) into catalog, and treat them with no difference. That's why you can not easily get label for an address in runtime. So even label are not treated as an additional data for an address...

    However since you mentioned label mask, you can checkout the merge option below, and use it to get an intersection of [prefab_label, filter_label].

    upload_2019-10-11_0-41-38.png

    upload_2019-10-11_0-42-1.png
     
    Djayp likes this.
  8. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    69