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

addressables throw InvalidKeyException on android platform

Discussion in 'Addressables' started by creepteks, Feb 9, 2020.

  1. creepteks

    creepteks

    Joined:
    Jun 2, 2017
    Posts:
    19
    I've incorporated Unity's addressable package into my project, but the issue I have is the addressables do not get loaded when I'm testing on android. The problem persists for all my addressable that I have, but in this special case, I want to load map texture (which is a huge texture in term of size) when the player opens the map, and unload it when he/she close it.
    the map initialize coroutine is as follows:
    Code (CSharp):
    1. public IEnumerator InitializeMapReferences()
    2.     {
    3.        // find map reference and Initialize it
    4.         _map = GameObject.FindGameObjectWithTag("MapCamera").GetComponent<MapManager>();
    5.         yield return StartCoroutine(_map.Initialize());
    6.     }
    here is the InitializeMap coroutine which makes sure all the core elements for map are available before I continue the flow:
    Code (CSharp):
    1. public IEnumerator Initialize()
    2.     {
    3.         // load map texture instance
    4.         var mapTextureInstanceLoad = m_mapTextureInstance.InstantiateAsync();
    5.         yield return mapTextureInstanceLoad;
    6.         m_mapTextureGameobject = mapTextureInstanceLoad.Result;
    7.    
    here is my addressableAssetSettings Here is the log from adb's logcat:
    Code (CSharp):
    1. E/Unity   (16787): Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[UnityEngine.GameObject], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=035a9d5a8d41d8b42a738cf8b98c7781
    2. E/Unity   (16787): UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    3. E/Unity   (16787): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    4. E/Unity   (16787): UnityEngine.Logger:LogFormat(LogType, String, Object[])
    5. E/Unity   (16787): UnityEngine.Debug:LogErrorFormat(String, Object[])
    6. E/Unity   (16787): UnityEngine.AddressableAssets.AddressablesImpl:LogException(AsyncOperationHandle, Exception) (at E:\mahmoud baghani\Payiz\Library\PackageCache\com.unity.addressables@1.5.0\Runtime\AddressablesImpl.cs:225)
    7. E/Unity   (16787): UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception) (at E:\mahmoud baghani\Payiz\Library\PackageCache\com.unity.addressables@1.5.0\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:286)
    8. E/Unity   (16787): UnityEngine.ResourceManagement.AsyncO
    9. E/Unity   (16787): Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<GameObject>: ChainOperation of Type: UnityEngine.GameObject failed because dependent operation failed
    10. E/Unity   (16787): Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=035a9d5a8d41d8b42a738cf8b98c7781
    11. E/Unity   (16787): UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    12. E/Unity   (16787): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    13. E/Unity   (16787): UnityEngine.Logger:LogFormat(LogType, String, Object[])
    14. E/Unity   (16787): UnityEngine.Debug:LogErrorFormat(String, Object[])
    15. E/Unity   (16787): UnityEngine.AddressableAssets.AddressablesImpl:LogException(AsyncOperationHandle, Exception) (at E:\mahmoud baghani\Payiz\Library\PackageCache\com.unity.addressables@1.5.0\Runtime\AddressablesImpl.cs:225)
    16. E/Unity   (16787): UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception) (at E:\mahmoud baghani\Payiz\Library\PackageCache\com.unity.addressables@1.5.0\Runtime\Resourc
    17. E/Unity   (16787): Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[UnityEngine.GameObject], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=adc44a52236cf704fab2efdb10c1c9e3
    18. E/Unity   (16787): UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    19. E/Unity   (16787): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    20. E/Unity   (16787): UnityEngine.Logger:LogFormat(LogType, String, Object[])
    21. E/Unity   (16787): UnityEngine.Debug:LogErrorFormat(String, Object[])
    22. E/Unity   (16787): UnityEngine.AddressableAssets.AddressablesImpl:LogException(AsyncOperationHandle, Exception) (at E:\mahmoud baghani\Payiz\Library\PackageCache\com.unity.addressables@1.5.0\Runtime\AddressablesImpl.cs:225)
    23. E/Unity   (16787): UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception) (at E:\mahmoud baghani\Payiz\Library\PackageCache\com.unity.addressables@1.5.0\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:286)
    24. E/Unity   (16787): UnityEngine.ResourceManagement.AsyncO
    25. E/Unity   (16787): NullReferenceException: Object reference not set to an instance of an object
    26. E/Unity   (16787):   at MapManager+<Initialize>d__53.MoveNext () [0x00101] in E:\mahmoud baghani\Payiz\Assets\Code\MapManager.cs:125
    27. E/Unity   (16787):   at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00020] in /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17
    28. E/Unity   (16787):
    29.  
    As you can see, this exceptions results in null references (like the one I've included inside the log I have posted) and make the game unplayable as I am relying on addressables to load/unload some of my core stuff like map textures or big render textures.
    The problem does not reveal itself in the editor. I've tried cleaning and rebuilding the addressables with no success. How should I go about solving this problem?

    UPDATE: I managed to fix the problem. Here is how I did it: The build script that is recommended by unity for builds is Packed mode. I had several asset groups, but the asset group that I used for the map textures, lacked a scheme. Adding a "content packing loading" scheme to my map asset group, and then "Build/new build/default build scrip" from addressables groups window solved the problem.
     
    Last edited: Feb 10, 2020
  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    583
    It tells you your key is
    035a9d5a8d41d8b42a738cf8b98c7781
    . Did you make your asset with that address? That looks like a guid or hash, not something you would make as your address.
     
  3. creepteks

    creepteks

    Joined:
    Jun 2, 2017
    Posts:
    19
    The problem was that I lacked a scheme on my map asset group. Adding the "content packing loading" to my group and rebuilding the addressables solved the problem. I've updated my post.
     
  4. miracletechteam1

    miracletechteam1

    Joined:
    Sep 18, 2019
    Posts:
    24
    Found the problem, it's because i'm reassigning the (in this case) AssetReferenceGameObject with new GameObject.
    Solution: remove/make it to none first > assign again

    How do i know?
    My PrefabModel and PrefabModels[0] is the same Gameobject but the AssetGUID is different likely not using the newer asset (still using the old one)
     

    Attached Files: