Search Unity

Addressables 1.4.0;Bug

Discussion in 'Addressables' started by a_bug_maker, Dec 10, 2019.

  1. a_bug_maker

    a_bug_maker

    Joined:
    Jan 4, 2016
    Posts:
    2
    "Hey! There's a bug that can't load a sprite successfully in "Use Asset Database(faster)" mode.
    The error happens in Addressables 1.4.0(It didn't happen in v1.3.8 or v1.3.3)

    Exception:
    upload_2019-12-10_13-56-48.png

    In Case 1 we can load a sprite by Addressables.LoadAssetAsync<Sprite>("Assets/Sprites/cells/u1.png") in all visions;

    But in Case 2, I try to load a sprite by Addressables.LoadAssetAsync<Sprite>("Assets/Sprites/cells/u1.png") (or by AssetReference.LoadAssetAsync<Sprite> way)in v1.4.0,it throw an exception as above.

    ps:"Simulate Group" mode and "Use Existing Build " mode can load a sprite properly in v1.4.0.
    ps:Addressables.LoadAssetAsync<Texture2D>("Assets/Sprites/cells/u1.png") works in v1.4.0.

    Case 1: Drag PNGs into a group
    upload_2019-12-10_12-5-9.png

    Case 2: Drag a folder contains PNGs
    upload_2019-12-10_12-6-20.png
     
  2. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Huh, that is very odd. Thanks for pointing this out. If you haven't already would you mind filing a bug with Unity and posting the case number here?
     
  3. a_bug_maker

    a_bug_maker

    Joined:
    Jan 4, 2016
    Posts:
    2
    (Case 1204628) [Bug]Addressable Assets System cann't load a sprite
    Ha-ha,it's my first time to send a bug report
     
    davidla_unity likes this.
  4. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Still getting this with 1.5.0, any eta on when this maybe fixed? thnx

    Is there a workaround in the meantime?
     
  5. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    KB73 likes this.
  6. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
  7. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Not as of yet, sorry. We do have a bug filed for the issue and are trying to get to it and others as quickly as possible.
     
    KB73 likes this.
  8. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    This still appears to be an issue for 1.6.0 :/ is there a workaround at all?
     
  9. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    This hasn't been fixed in 1.6.0 yet!? So disappointing...
    I am still on 1.3.8 because of this issue.
     
  10. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Our only workaround was to keep people on 1.3.8 and put the external builds ( by changing the manifest at build time ) to 1.6.0
     
    chanon81 likes this.
  11. rg_johnokane

    rg_johnokane

    Joined:
    Oct 10, 2018
    Posts:
    11
    The issue seems to reside in BuildScriptFastMode. When performing GatherAssetsForFolder it doesn't make use of the AddressableAssetEntry.CreateCatalogEntries - which does the job of adding multiple locations (the first of each type of asset found for the guid/file - and all those subobject addresses). This hits sprites, or fbx files etc. A special exception is made for the SpriteAtlas. So a hack/work around for now, is to also include the scenario where a Texture2D is found too.

    Something like this:

    Code (CSharp):
    1.         private void GatherAssetsForFolder(AddressableAssetEntry entry, AddressableAssetsBuildContext aaContext)
    2.         {
    3.             var allEntries = new List<AddressableAssetEntry>();
    4.             entry.GatherAllAssets(allEntries, false, true, true);
    5.             foreach (var e in allEntries)
    6.             {              
    7.                 var type = e.MainAssetType;
    8.  
    9.                 if(type == typeof(SpriteAtlas))
    10.                     e.CreateCatalogEntries(aaContext.locations, false, typeof(AssetDatabaseProvider).FullName, null, null, aaContext.providerTypes);
    11.                 //### HACK_START
    12.                 else if (type == typeof(Texture2D))
    13.                     e.CreateCatalogEntries(aaContext.locations, false, typeof(AssetDatabaseProvider).FullName, null, null, aaContext.providerTypes);
    14.                 //### HACK_END
    15.                 else
    16.                 {
    17.                     if (e.IsScene)
    18.                         type = typeof(SceneInstance);
    19.                     aaContext.locations.Add(new ContentCatalogDataEntry(type, e.AssetPath, typeof(AssetDatabaseProvider).FullName, e.CreateKeyList()));
    20.                 }
    21.             }
    22.         }
    23.  
     
  12. magmagma

    magmagma

    Joined:
    Oct 27, 2017
    Posts:
    41
    I thought this was a problem only with 1.6.2 because I had been waiting on updating until now and came across the problem, but indeed I just checked and it had to go back to 1.3.8 for it to work correctly.
     
  13. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    I've got a high priority bug put in to look at this. I can't make any promises as to when we'll get to it (hopefully soon, I just can't say for sure). Hopefully the workaround posted above will work for anyone running into this problem. I'm sure that's not the news you were hoping for so I apologize for that.
     
    KB73 likes this.
  14. organick

    organick

    Joined:
    Jul 17, 2012
    Posts:
    17
    I'm facing a similar issue.
    Not the exact same repro, since I'm using labels and I'm trying to load sprites as sub-assets from a png.

    Code (CSharp):
    1.  
    2. Addressables.LoadAssetsAsync<IList<Sprite>>(
    3.   keys: new string[] { "decor", "sprites" },
    4.   callback: this.OnDecorSpriteLoaded,
    5.   mode: Addressables.MergeMode.Intersection);
    6.  
    addressables.PNG

    Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[System.Collections.Generic.IList`1[System.Collections.Generic.IList`1[UnityEngine.Sprite]]], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=System.String[], Type=System.Collections.Generic.IList`1[UnityEngine.Sprite]
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:<.ctor>b__33_0(AsyncOperationHandle)
    DelegateList`1:Invoke(AsyncOperationHandle) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.AddressableAssets.Initialization.<>c__DisplayClass13_0:<LoadContentCatalogInternal>b__0(AsyncOperationHandle`1)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.ResourceManagement.ChainOperation`2:OnWrappedCompleted(AsyncOperationHandle`1)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:19)
     
    Last edited: Feb 24, 2020
  15. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    k so the way we worked is to add
    1. else if (type == typeof(Texture2D))
    2. e.CreateCatalogEntries(aaContext.locations, false, typeof(AssetDatabaseProvider).FullName, null, null, aaContext.providerTypes);
    3. //### HACK_END
    into BuildFastMode as instructed above and in our AssetManager, we passed in the InternalID from the IResourceLocator if the thing is a sprite, just using an IResourceLocator directly works for every assets but sprites and this finally fixed the issue for us.

    e.g LoadAssetAsync<Sprite>( obj.InternalID )

    thnx
     
  16. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    So has this been fixed in the new Addressables 1.7.4?
     
  17. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Nope still happens in 1.7.4 but you can workaround it like i did above...embed the addressables package into your project then add the #HACK stuff - you can check this into source control and everyone will get the change..

    Then load the sprites via the internalId from the ResourceLocator ( this is just the path in the addressables dialog ) and it works for us...there maybe other workarounds but that will get you going, this runs on 1.6.2
     
    chanon81 likes this.
  18. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    I think I've stumbled upon the same issue. But in my case I'm trying to load ScriptableObject sub-assets by label. There are multiple things broken with this:

    • The catalog itself seems to have no information about sub-asset names. It might have worked (if not for the issue #2) if all sub-assets were of different types (because the system can load different sub-assets from the exact same path in bundle but different object types). But if there are multiple sub-objects of the same type, only the first one can be loaded because it's not possible to distinguish them at run-time.
    • The loading logic is bugged if you try to load for example a ScriptableObject with one sub-object of different type. It will correctly generate a list of 2 IResourceLocation (the same InternalId, different ResourceType), but load the same object twice. This also leads to Addressable Event Viewer crashing. This happens because the load operation for the second asset is not started, it erronously returns the same operation from cache (IResourceLocation Hashing logic doesn't take ResourceType into account).
    • Related to both of the above: build scripts add catalog entries for each sub-object, but only once of each unique type. This leads to issue #2 loading the same object twice. The reason for doing it this way also eludes me.

    Please fix this. The original issue was reported 4 months ago!

    PS: worked around this for the moment by calling ResourceManager.ProviderResource<IList<Object>>() for each IResourceLocation that is not a prefab and then calling ResourceManager.CreateGenericGroupOperation. There are special cases for this built into resource providers that return all objects at path if you request an IList<T>. Then I can just flatten the results. Still, some of the above issues needs fixing.
     
    Last edited: Apr 26, 2020
    chanon81 and oscarAbraham like this.
  19. c0nd3v

    c0nd3v

    Joined:
    May 8, 2019
    Posts:
    30
  20. AriyaSD

    AriyaSD

    Joined:
    Nov 2, 2019
    Posts:
    24
    I've resorted to using 1.8.5's BuildScriptFastMode with Addressables 1.16.6 for now. It only needs a minor change to work. In BuildDataImplementation(), there's this code:

    Code (CSharp):
    1. var aaContext = new AddressableAssetsBuildContext
    2.             {
    3.                 settings = aaSettings, //obsolete
    4.                 runtimeData = new ResourceManagerRuntimeData(),
    5.                 bundleToAssetGroup = null,
    6.                 locations = new List<ContentCatalogDataEntry>(),
    7.                 providerTypes = new HashSet<Type>()
    8.             };
    AddressableAssetsBuildContext.settings is obsolete, so just replace it with the property "Settings":

    Code (CSharp):
    1. var aaContext = new AddressableAssetsBuildContext
    2.             {
    3.                 Settings = aaSettings,
    4.                 runtimeData = new ResourceManagerRuntimeData(),
    5.                 bundleToAssetGroup = null,
    6.                 locations = new List<ContentCatalogDataEntry>(),
    7.                 providerTypes = new HashSet<Type>()
    8.             };