Search Unity

Resolved InvalidKeyException, trouble with simple Addressables use case (lots of pictures!)

Discussion in 'Addressables' started by Endahs, May 17, 2020.

  1. Endahs

    Endahs

    Joined:
    Sep 16, 2014
    Posts:
    94
    Hi folks, hoping someone can point me in the right direction because I've been searching for a solution for hours for what should be a simple Addressables use case.

    I've installed the latest Addressables 1.8.3:
    upload_2020-5-17_12-45-28.png


    I've created an Addressables Group called "CORE", set it as default. I've added a single file to it, an XML document called symbiote.xml and changed the Addressable Name to "coreXML":
    upload_2020-5-17_12-46-10.png


    The Addressable Group has the usual configuration, and I have built the Addressables in the Addressables GUI using the default build scripts. I've also cleared the cache and re-built just to be sure:
    upload_2020-5-17_12-47-28.png


    I have a simple LoadAssetAsync request, using type XmlDocument and passing in assetName (a string, representing the key I want to use, in this case "coreXML":
    Code (CSharp):
    1. // Core function that imports XML data, should only run if it has not been imported yet!
    2.     internal static void ImportXMLData( string assetName )
    3.     {
    4.         string hereParams = here + "ImportXMLData(assetName: " + assetName.ToString() + "): ";
    5.         ReportingAPI.RecordNotice( hereParams + "Fired!" );
    6.  
    7.         // Validation...
    8.         if( string.IsNullOrWhiteSpace( assetName ) )
    9.         {
    10.             ReportingAPI.RecordError( hereParams + "assetName was null or blank!" );
    11.             return;
    12.         }
    13.         else if( dataHasBeenImported )
    14.         {
    15.             // Data was already imported! Why are you trying again?
    16.             ReportingAPI.RecordError( hereParams + "dataHasBeenImported is already TRUE, why are you trying again?" );
    17.             return;
    18.         }
    19.  
    20.         Addressables.LoadAssetAsync<XmlDocument>( assetName ).Completed += Event_DatafileLoaded;
    21.  
    22.     }

    But no matter what I try, I always get a InvalidKeyException and a failure in the asset load:

    Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[System.Xml.XmlDocument], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=coreXML, Type=System.Xml.XmlDocument
    UnityEngine.AddressableAssets.Addressables:LoadAssetAsync(Object)
    DataImporterAPI:ImportXMLData(String) (at Assets/Symbiote/Core/Code/DataImporterAPI.cs:57)
    BootAPI:Event_AddressablesInitialized(AsyncOperationHandle) (at Assets/Symbiote/Core/Code/BootAPI.cs:99)
    DelegateList`1:Invoke(AsyncOperationHandle) (at Library/PackageCache/com.unity.addressables@1.8.3/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.AddressableAssets.Initialization.<>c__DisplayClass14_0:<LoadContentCatalogInternal>b__0(AsyncOperationHandle`1)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.8.3/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.8.3/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.8.3/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:19)

    What am I missing here? Why does the key "coreXML" fail? Is there any way of seeing what keys Addressables is aware of at runtime?


    I've also tried create an AssetReference and passing in "coreXML" as the key, then using the AssetReference to pass in as a key but I get the same issue: "coreXML" fails to be found as a key.

    Any help would be super appreciated :)
     

    Attached Files:

  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Is
    XmlDocument
    a system type? I don't think Unity supports that. So I think what you want to do is
    Addressables.LoadAssetAsync<TextAsset>
    then parse the textAsset.text.
     
    Endahs likes this.
  3. Endahs

    Endahs

    Joined:
    Sep 16, 2014
    Posts:
    94
    This was absolutely it. THANK YOU ProtoTerminator. Appreciate you taking the time to help.