Search Unity

Duplicate resource locations from label query

Discussion in 'Addressables' started by Paul_H23, Aug 21, 2019.

  1. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    Hi,

    Hitting a weird problem. I've added a couple of textures to my addressables, named them with "Bkg/<name>" and given them both the label "Background". When I ask for resource locations based on label, like below, I get a count of 4, and each one is returned twice. Am I missing something here?

    Code (CSharp):
    1.         Addressables.LoadResourceLocationsAsync("Background").Completed += (AsyncOperationHandle<IList<IResourceLocation>> result) =>
    2.         {
    3.             Debug.Log(result.Result.Count);
    4.             foreach (IResourceLocation resource in result.Result)
    5.             {
    6.                 Debug.LogFormat("Background: {0}", resource.PrimaryKey);
    7.                 Addressables.LoadAssetAsync<Texture2D>(resource).Completed += (AsyncOperationHandle<Texture2D> bkg) =>
    8.                 {
    9.                     Debug.LogFormat("Background Loaded: {0}", resource);
    10.                 };
    11.             }
    12.         };
    13.  
     
  2. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    On closer investigation, it seems that one of each of the duplicates is coming back as a UnityEngine.Sprite resource type, and the other a UnityEngine.Texture2D resource type. So I have a workaround, but is this behaviour documented anywhere?


    Paul
     
  3. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    As I remembered it mentioned in the CHANGELOG.md in some way.

    It happens since introducing the LoadResourceLocatinosAsync with the type argument. Unless specific a type, the asset and sub-asset locations are both returned with type=null. So it's intended.

    ```
    public static AsyncOperationHandle<IList<IResourceLocation>> LoadResourceLocationsAsync(IList<object> keys, MergeMode mode, Type type = null)
    ```
     
    unity_bill likes this.
  4. mrekuc

    mrekuc

    Joined:
    Apr 17, 2009
    Posts:
    116
    @Favo-Yang
    I'm not understanding this either. I have 1 group with 11 GameObject prefabs. When i use AsyncOperationHandle<IList<IResourceLocation>> handle = Addressables.LoadResourceLocationsAsync(tag, typeof(GameObject));

    the result is 22. I have tried everything to prevent duplivate locations but always ends up being 22. Why are they duplicating?
     
  5. mrekuc

    mrekuc

    Joined:
    Apr 17, 2009
    Posts:
    116
    I was using 1.16.15 and had this issue. I tried the 1.17.2-preview and this issue was resolved.
     
  6. mrekuc

    mrekuc

    Joined:
    Apr 17, 2009
    Posts:
    116
    Nevermind. Built new ones and it went back to double. Weird that the old build worked until I rebuilt it again.
     
  7. brian_imvizar

    brian_imvizar

    Joined:
    Jan 15, 2022
    Posts:
    3
    Having this issue with 2021.3.4f1 with remotely-loaded scriptableobject assets