Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature request? Getting access to component types without loading the asset

Discussion in 'Addressables' started by elijad, Apr 17, 2020.

  1. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    Basically, wanted to discuss the possibility of such feature as caching some component info for prefabs in the addressable system.

    Right now I'm using the resource location map directly to find all locations for assets of specified type and then build lists based on that/ load the first one without bothering with location names and other details.
    Like this:

    Code (CSharp):
    1. public static List<IResourceLocation> FindLocationsOfType(Type t)
    2.     {
    3.         List<IResourceLocation> output = new List<IResourceLocation>();
    4.  
    5.         foreach (var locator in Addressables.ResourceLocators)
    6.         {
    7.             if (locator is ResourceLocationMap map)
    8.             {
    9.                 foreach (var key in map.Keys)
    10.                 {
    11.                     if (t.IsAssignableFrom(map.Locations[key][0].ResourceType))
    12.                     {
    13.                         if (!output.Any(location => location.InternalId == map.Locations[key][0].InternalId))
    14.                         {
    15.                             output.Add(map.Locations[key][0]);
    16.                         }
    17.                     }
    18.                 }
    19.             }
    20.         }
    21.  
    22.         return output;
    23.     }
    And this works great. I can find all instances of a specific scriptable object and even generic interface implementations for specific types.
    It would be super useful if you could also find components inside prefabs this way, however the addressable system only caches the asset type and not the component types.

    After looking at IResourceLocation interface, caching component types seems rather tricky to implement without changing big chunks of the system, but I still wonder if anyone on the unity team would see this as a necessary feature.
     
    phobos2077 likes this.
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,816
    We'll send this feature request over to the team for them to check out! Thank you so much for the feedback!
     
  3. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    I actually implemented it as a separate system, but still I think it might be nice to have some extra metadata on what you're loading readily available. Thanks for the attention anyway.
     
  4. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,816
    For sure. I spoke with the team about this. Can you share a specific use case for needing cached component types?
     
  5. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    It allows you to find all prefab locations with a certain component without actually loading them. So, useful for building lists, creating singletons and in general more reliable than string referencing. Of course, that was not quite the purpose of the addressable system, but I found that feature very useful so far with my code.