Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Addressables Stops working after adding Assembly Definitions to Project

Discussion in 'Addressables' started by rtm223, Jan 23, 2020.

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

    rtm223

    Joined:
    Apr 12, 2017
    Posts:
    28
    Update: This is a bug in the Addressables system that breaks addressable content if the scripts defining the assets are moved to a different assembly. Should be possible to fix up, as it's a pretty nasty edge case to have to identify and fix manually.


    Summary:
    I moved some code files into a new assembly and now can't load the assets that are based upon them them through the addressables system

    Unity 2018.4.0f1, Addressables 1.5.1

    Probably I've messed up something very basic here as this is my first time using Assembly Definitions, and I'm pretty new to addresables, but this is my issue:

    I'm currently loading 2 types of custom asset through the addressables system (both inherit from ScriptableObject)
    - RTM.Localization.LocalizationSettings
    - RTM.Utilities.StringArrayAsset

    I'm migrating my various modules into packages, so have started by splitting up the code into assemblies. This means the StringArrayAsset.cs file is in a new Assembly (RTM.Common). LocalizationSettings.cs is still in Assembly-CSharp (for now).

    All the assets live in the main project folder (away from any assembly definitions) and I have rebuilt the Addressables content and checked all the addressables settings seem the same as before.

    After moving the code into my new assembly, I can still load LocalizationSettings, but not any of my StringArrayAsset assets. The assets look fine in inspector and I can still use them as direct references, but can't load them via adressables

    Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[RTM.Utilities.StringArrayAsset], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=rtm/loc/strings/checkpoint
    UnityEngine.AddressableAssets.Addressables:LoadAssetAsync(Object)


    rtm/loc/strings/checkpoint is correctly set up as an address in the Addressables Settings. Error occurs in both editor and player. The LocalizationSettings loads fine
     
    Last edited: Jan 23, 2020
  2. rtm223

    rtm223

    Joined:
    Apr 12, 2017
    Posts:
    28
    Oh hey, I apparently fixed this by accident, BUT there appears to be a pretty major bug/flaw here. All these assets are auto-generated and after a re-generation their serialised data has changed (which wouldn't normally happen unless the source changes (see partial diff below)

    upload_2020-1-23_20-50-16.png

    I don't know what that field is, but after this update (and a rebuild of my addressables), all my addressables loading works fine.

    The major flaw here is that if you migrate a script between Assemblies all user data based upon it silently breaks?? This is not an issue for me right now, but if this was actual user data it would be a massive pain to re-create all the files manually

    UPDATE: actually, that's not the only change. After migrating the other script I found that the probable culprit is the AddressableAssetGroup settings. Turns out the Assembly is serialized in there but hidden from view and does not get ujpdated unless you a:
    - Set the asset non-addressable, set it addressable and put it back in the correct group, OR
    - Edit the serialised file directly (eeek)

    upload_2020-1-23_21-59-15.png

    Seeing as the AddressableAssetGroup has the GUID of the asset, it can actually look up the script and do an automatic fixup if needs be? I'm not sure when this happens but I guess this is now clearly a bug
     
    Last edited: Jan 23, 2020
  3. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    This happens with plain AssetBundles: if a class is moved to another assembly, bundles which reference them will not be able to find them until you force them to be rebuilt.
     
  4. rtm223

    rtm223

    Joined:
    Apr 12, 2017
    Posts:
    28
    This is not a case of forcing them to be rebuilt, you have to manually set everything up again despite everything looking correct in the editor.

    I'm suggesting that the bug is that rebuilding DOESN'T fix it with Addressables.
     
    funbites likes this.
  5. funbites

    funbites

    Joined:
    Oct 9, 2015
    Posts:
    17
    I'm having the same problem. Thanks!
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    Well, Unity definitely should handle that, because it's HUUUUGE pain recheck addressable assets manually. I'm faced with same problem today, when I added asmdefs for including unit tests. @DavidUnity3d or you can suggest any thing?
     
    FlightOfOne and phobos2077 like this.
  7. BonitaPersona

    BonitaPersona

    Joined:
    Feb 20, 2014
    Posts:
    16
    I also want to point out how hard this is to trace down. In my case it throws an InvalidKeyException on some sprites, which I'm not sure what may the reason behind be. I've spent a long while trying to trace this back to check which asset or GUID (the Key) is, inside the Addressables package, and couldn't find a way to.

    On the other hand, I also failed trying to write down a rule.

    I know for a fact that asmdefs are causing this, because just adding or removing them (changing repo branch, with no other changes whatsoever) fixes and unfixes the situation.
     
  8. RZGames_Jethro

    RZGames_Jethro

    Joined:
    Jul 6, 2017
    Posts:
    87
    you can open addressable packages with notepad and search for the GUID.
     
  9. PeppeJ2

    PeppeJ2

    Joined:
    May 13, 2014
    Posts:
    41
    Did someone end up finding a proper solution to this? I think I've run in to the same issue myself. Failing to load an asset due to invalid key yet it's set up correctly, but it is compiled under a different assembly.
     
    Se7eNHea7eN likes this.
Thread Status:
Not open for further replies.