Search Unity

Loading sprites via AssetReferenceAtlasedSprite broken after upgrade to 1.8.3

Discussion in 'Addressables' started by cgaudino, Apr 21, 2020.

Thread Status:
Not open for further replies.
  1. cgaudino

    cgaudino

    Joined:
    Jan 17, 2014
    Posts:
    4
    Hello all,

    I'm working on a project in Unity 2019.3.10 that makes heavy use of loading atlased sprites via AssetReferenceAtlasedSprite's LoadAssetAsync.

    Our project works fine with addressables version 1.7.5, but with version 1.8.3 all sprite loads fail with an InvalidKeyException. I also tested in an empty project and had the same issues.

    Was the workflow for loading sprites from an addressable atlas changed in this version, or is this a bug?
     
    chanon81 and Upian like this.
  2. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    328
    I suggest to report this as a bug via Unity's "Help -> Report a bug".
     
  3. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,676
  4. cgaudino

    cgaudino

    Joined:
    Jan 17, 2014
    Posts:
    4
    Thanks, I filed the bug and attached a sample project (Case 1242137).
     
    chanon81 likes this.
  5. LilMako17

    LilMako17

    Joined:
    Apr 10, 2019
    Posts:
    37
    I can also confirm I'm seeing this issue. Using AssetReference to load atlased sprites also result in the same issue. Loading sprites that are not part of an atlases works. Hope you guys can get this fixed soon. I really liked the improvements to the asset reference editor drawer in 1.8.3, i'd like to use them!
     
  6. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    36
    Hey,
    if the developers find a quick fix, please post it. We want to update to 1.8.3 because of the other bugfixes and the nice new features but this breaks a lot in our game right now :)

    We would like to fix it with a local addressable package.

    Thanks for your help!
     
  7. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    36
    I found a "fix" which works for now:

    1. Add the following lines to the AddressableAssetEntry class in line 663:
    Code (CSharp):
    1.  
    2. if (mainType == typeof(SpriteAtlas))
    3. {
    4.       providerTypes.Add(typeof(AtlasSpriteProvider));
    5. }
    6.  
    2. Replace line 51 in the DynamicResourceLocator class with:
    Code (CSharp):
    1. locations.Add(new ResourceLocationBase(locName, subKey, typeof(AtlasSpriteProvider).FullName, type, new IResourceLocation[] { mainLoc }));
    Basically the AtlasSpriteProvider was not available anymore at runtime. So the first change readds this (got the code from version 1.7.4 in the same method). Furthermore the AtlasSpriteProvider uses the id of the resource location to load the sprite from the atlas but the whole key (including the sprite atlas key) was used.

    It is working in the editor for each mode and I will test it on devices too.
     
  8. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    36
    Fix for 1.9.2:

    Class DynamicResourceLocator, replace Line 51:
    Code (CSharp):
    1. locations.Add(new ResourceLocationBase(locName, subKey, typeof(AtlasSpriteProvider).FullName, type, new IResourceLocation[] { mainLoc }));
    Class InitializationOperation, add the following line underneath the other providers in line 50:
    Code (CSharp):
    1. aa.ResourceManager.ResourceProviders.Add(new AtlasSpriteProvider());
     
    miracletechteam1 likes this.
  9. qoqgames

    qoqgames

    Joined:
    Aug 23, 2020
    Posts:
    4
Thread Status:
Not open for further replies.
unityunity