Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Addressable assets won't load in build

Discussion in 'Addressables' started by Leonetienne500, Dec 5, 2019.

  1. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    125
    Hey, so i have a bunch of .jpg Textures stored in "Assets/Addressables/icon/<id>.jpg.

    I am loading them using the Addressables system.
    Code (CSharp):
    1. Addressables.LoadAsset<Texture>(path).Completed += callbackMethod;
    Loading them works fine in playmode, but as soon as i build (to android), they just won't load.

    I've found the Addressable Assets management window, where i changed the "playmode script" to "Packed Play Mode", tried to build the assets (Build => Build Player Content), but this just results in an argumentException error message reading "An item with the same key has already been added. ...."
    Full error message: https://pastebin.com/YVNppkdi

    How can i fix this?

    EDIT:
    I've also tried to build it for windows, to see if it was an android related issue. It does not work on a windows build either.
    The full path of the .jpgs does not exceed 255 characters. Regarding windows MAX_PATH issue.
     
    Last edited: Dec 5, 2019
  2. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    125
    So, i closed unity (because it was frozen... again), deleted all the 15.000 icons, opened unity again and put one single icon in to test. The bundle COMPILED!
    Then i went up to 20 icons. It compiled!
    Next step, 1500 icons. It compiled again.
    Then i went ahead and put in all the 15000 icons back in again. And... it compiled..? Wtf

    First off, somehow my 60mb worth of icons compressed down to 330mb? wtf unity?

    Next i built the project to my phone aaaaad it works! Really happy!
     
  3. Litovets

    Litovets

    Joined:
    Sep 3, 2012
    Posts:
    20
    Also can't make it work in build for Android. There are a lot of exceptions:
    Code (CSharp):
    1. 12-05 18:38:57.840 31579 31604 E Unity   : Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[UnityEngine.Object], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=a0638f04b98b8854b930eefbda31d30c
    2. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngine.AddressableAssets.AddressablesImpl:LogException(AsyncOperationHandle, Exception)
    3. 12-05 18:38:57.840 31579 31604 E Unity   : System.Action`2:Invoke(T1, T2)
    4. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception)
    5. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:Complete(TObject, Boolean, String)
    6. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:InvokeExecute()
    7. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:Start(ResourceManager, AsyncOperationHandle, DelegateList`1)
    8. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngine.ResourceManagement.ResourceManager:StartOperation(AsyncOperationBase`1, AsyncOperationHandle)
    9. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngine.AddressableAssets.AddressablesImpl:LoadAssetAsync(Object)
    10. 12-05 18:38:57.840 31579 31604 E Unity   : System.Func`2:Invoke(T)
    11. 12-05 18:38:57.840 31579 31604 E Unity   : UnityEngi
    12. 12-05 18:38:57.846 31579 31604 E Unity   : Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[UnityEngine.Object], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=e2dfa85217e0a474da536b2f0afc5ea9
    13. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngine.AddressableAssets.AddressablesImpl:LogException(AsyncOperationHandle, Exception)
    14. 12-05 18:38:57.846 31579 31604 E Unity   : System.Action`2:Invoke(T1, T2)
    15. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception)
    16. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:Complete(TObject, Boolean, String)
    17. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:InvokeExecute()
    18. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:Start(ResourceManager, AsyncOperationHandle, DelegateList`1)
    19. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngine.ResourceManagement.ResourceManager:StartOperation(AsyncOperationBase`1, AsyncOperationHandle)
    20. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngine.AddressableAssets.AddressablesImpl:LoadAssetAsync(Object)
    21. 12-05 18:38:57.846 31579 31604 E Unity   : System.Func`2:Invoke(T)
    22. 12-05 18:38:57.846 31579 31604 E Unity   : UnityEngi
    23. 12-05 18:38:57.849 31579 31604 E Unity   : Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<Object>: ChainOperation of Type: UnityEngine.Object failed because dependent operation failed
    24. 12-05 18:38:57.849 31579 31604 E Unity   : Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=a0638f04b98b8854b930eefbda31d30c
    25. 12-05 18:38:57.849 31579 31604 E Unity   : UnityEngine.AddressableAssets.AddressablesImpl:LogException(AsyncOperationHandle, Exception)
    26. 12-05 18:38:57.849 31579 31604 E Unity   : System.Action`2:Invoke(T1, T2)
    27. 12-05 18:38:57.849 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception)
    28. 12-05 18:38:57.849 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:Complete(TObject, Boolean, String)
    29. 12-05 18:38:57.849 31579 31604 E Unity   : System.Action`1:Invoke(T)
    30. 12-05 18:38:57.849 31579 31604 E Unity   : DelegateList`1:Invoke(T)
    31. 12-05 18:38:57.849 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:InvokeCompletionEvent()
    32. 12-05 18:38:57.849 31579 31604 E Unity   : UnityEngine.ResourceManagement.ResourceManager:ExecuteDeferredCallbacks()
    33. 12-05 18:38:57.849 31579 31604 E Unity   : UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    34. 12-05 18:38:57.849 31579 31604 E Unity   : System.Action`1:Invoke(T)
    35. 12-05 18:38:57.849 31579 31604 E Unity   :
    36. 12-05 18:38:57.849 31579 31604 E Unity   : (Filename: ./Runtime/Export/De
    37. 12-05 18:38:57.852 31579 31604 E Unity   : Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<Object>: ChainOperation of Type: UnityEngine.Object failed because dependent operation failed
    38. 12-05 18:38:57.852 31579 31604 E Unity   : Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=e2dfa85217e0a474da536b2f0afc5ea9
    39. 12-05 18:38:57.852 31579 31604 E Unity   : UnityEngine.AddressableAssets.AddressablesImpl:LogException(AsyncOperationHandle, Exception)
    40. 12-05 18:38:57.852 31579 31604 E Unity   : System.Action`2:Invoke(T1, T2)
    41. 12-05 18:38:57.852 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:set_OperationException(Exception)
    42. 12-05 18:38:57.852 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:Complete(TObject, Boolean, String)
    43. 12-05 18:38:57.852 31579 31604 E Unity   : System.Action`1:Invoke(T)
    44. 12-05 18:38:57.852 31579 31604 E Unity   : DelegateList`1:Invoke(T)
    45. 12-05 18:38:57.852 31579 31604 E Unity   : UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:InvokeCompletionEvent()
    46. 12-05 18:38:57.852 31579 31604 E Unity   : UnityEngine.ResourceManagement.ResourceManager:ExecuteDeferredCallbacks()
    47. 12-05 18:38:57.852 31579 31604 E Unity   : UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    48. 12-05 18:38:57.852 31579 31604 E Unity   : System.Action`1:Invoke(T)
    Ut the Editor works fine. Can anyone help me? Thanks!

    UPD: Version of Addressables package is 1.4.0
     
  4. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    125
    Honestly, this is just bad design from unity.
    It will work in the editor with no problems, but to get it to work in Build, you have to navigate to (in the top bar) Window -> Asset Management -> Addressables -> (new windows top bar) Build -> Build Player Content

    This is where i got the exception that seemed to disappear after manually re-importing everything.
    If you don't build the addressables, they won't be included in the build, hence you get a lot of InvalidKeyExceptions, because the assets corresponding to the keys are not present in the build.

    Unity could at least pop a little message box when building "oi, m8 watch out you haven't built your player content" but it builds without a warning.

    Yes, for every change you make to the addressable assets, you have to build the player content again
     
  5. Litovets

    Litovets

    Joined:
    Sep 3, 2012
    Posts:
    20
    Deleted AddressableAssetsData folder and recreated it - it fixed building of asset bundles.
    But new problem now - loading of assets doesn't work if selected Play Mode script - Use Existing Build (requires build groups). Every load request stops on PercentComplete = 0.5 and IsDone = false. I've tried many options - Local Build Path and Local Load Path, Remote and Remote and so on - the same result. Is it known issue?

    UPD: Just tested - loading assets doesn't work in build too. No errors, just stuck on load.
     
    Last edited: Dec 6, 2019
  6. Litovets

    Litovets

    Joined:
    Sep 3, 2012
    Posts:
    20
    UP! Any answer please?
     
  7. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    535
    It's not a bad design if you know what has to be done to make this work.
    the addressable asset system uses asset bundles. Basically putting assets into bundles and compressing them.
    Bundles aren't made magically and people with large projects don't want addressable building to be forced when making a new player build. Hence this has to be done manually using the menu. However, if you still want it to be automatically built upon building the player you can make a simple pre-processing build script using the IPreProcessingBuildWithReport interface. https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.html

    For me I have a custom build tool which I can specify whether I'd want to clean the addressables and rebuild them or just incrementally build them. All you have to do is call the right API.
    So I'm quite glad it isn't forced upon building the player, if I really want to build the addressables I want to be in control of that rather than Unity. Why not make it a setting then? you'd probably ask. Well if someone else in source control turns it on and someone else wants it off but doesn't notice that before building they'd be sitting there building the addressables which could take hours for that person. It's a setting that is hidden somewhere in the addressables settings which does something to your build process. imho none should want that. Hence if you really want it you should build a tool yourself that does this for you. It's all about control and where you put that control.

    Are you referencing the assets through public AssetReference fields in your script or are you loading them using a string key?
    Posting some code would be useful together with a small screenshot of your addressable setup & bundle settings of what you're trying to load.
     
  8. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    125
    It should not build automaticly for every build. It shouldn't be a setting either.

    But it for sure should pop a little Debug.LogWarning if you build without any compiled player content at all! Maybe make that an option to turn off the LogWarning! What would be the downsides of that?
     
    RaL and chanon81 like this.
unityunity