Search Unity

NullReferenceException when doing LoadAssetAsync() after upgrading to 1.0

Discussion in 'Localization Tools' started by _eternal, Sep 18, 2021.

  1. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    I have a piece of code that stopped working in build recently (still works correctly in editor). It worked when I was on the preview builds of the Localization package, but it seems to have broken after upgrading to 1.0.0 and 1.0.1. This is Unity 2020.3.14.

    The full error is below:
    Code (CSharp):
    1. NullReferenceException
    2.   at (wrapper managed-to-native) UnityEngine.Object.GetName(UnityEngine.Object)
    3.   at UnityEngine.Object.get_name () [0x00001] in C:\buildslave\unity\build\Runtime\Export\Scripting\UnityEngineObject.bindings.cs:194
    4.   at UnityEngine.Localization.Tables.LocalizationTable.VerifySharedTableDataIsNotNull () [0x00011] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Tables\LocalizationTable.cs:154
    5.   at UnityEngine.Localization.Tables.LocalizationTable.FindKeyId (System.String key, System.Boolean addKey) [0x00001] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Tables\LocalizationTable.cs:147
    6.   at UnityEngine.Localization.Tables.DetailedLocalizationTable`1[TEntry].GetEntry (System.String key) [0x00001] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Tables\DetailedLocalizationTable.cs:469
    7.   at UnityEngine.Localization.Tables.DetailedLocalizationTable`1[TEntry].GetEntryFromReference (UnityEngine.Localization.Tables.TableEntryReference entryReference) [0x0002d] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Tables\DetailedLocalizationTable.cs:458
    8.   at UnityEngine.Localization.GetTableEntryOperation`2[TTable,TEntry].ExtractEntryFromTable (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] asyncOperation) [0x00037] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Operations\GetTableEntryOperation.cs:62
    9.   at UnityEngine.Localization.GetTableEntryOperation`2[TTable,TEntry].Execute () [0x00080] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Operations\GetTableEntryOperation.cs:50
    10.   at UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].InvokeExecute () [0x00001] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.addressables@1.19.4\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:474
    11.   at UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].Start (UnityEngine.ResourceManagement.ResourceManager rm, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency, DelegateList`1[T] updateCallbacks) [0x000a1] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.addressables@1.19.4\Runtime\ResourceManager\AsyncOperations\AsyncOperationBase.cs:469
    12.   at UnityEngine.ResourceManagement.ResourceManager.StartOperation[TObject] (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject] operation, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency) [0x00001] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.addressables@1.19.4\Runtime\ResourceManager\ResourceManager.cs:458
    13.   at UnityEngine.Localization.Settings.LocalizedDatabase`2[TTable,TEntry].GetTableEntryAsync (UnityEngine.Localization.Tables.TableReference tableReference, UnityEngine.Localization.Tables.TableEntryReference tableEntryReference, UnityEngine.Localization.Locale locale, UnityEngine.Localization.Settings.FallbackBehavior fallbackBehavior) [0x00041] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Settings\Database\LocalizedDatabase.cs:467
    14.   at UnityEngine.Localization.Settings.LocalizedAssetDatabase.GetLocalizedAssetAsyncInternal[TObject] (UnityEngine.Localization.Tables.TableReference tableReference, UnityEngine.Localization.Tables.TableEntryReference tableEntryReference, UnityEngine.Localization.Locale locale, UnityEngine.Localization.Settings.FallbackBehavior fallbackBehavior) [0x00001] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Settings\Database\LocalizedAssetDatabase.cs:96
    15.   at UnityEngine.Localization.Settings.LocalizedAssetDatabase.GetLocalizedAssetAsync[TObject] (UnityEngine.Localization.Tables.TableReference tableReference, UnityEngine.Localization.Tables.TableEntryReference tableEntryReference, UnityEngine.Localization.Locale locale, UnityEngine.Localization.Settings.FallbackBehavior fallbackBehavior) [0x00001] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Settings\Database\LocalizedAssetDatabase.cs:69
    16.   at UnityEngine.Localization.LocalizedAsset`1[TObject].LoadAssetAsync () [0x0000c] in C:\gamedev\unity\monospaced-lovers\Library\PackageCache\com.unity.localization@1.0.1\Runtime\Localized Reference\LocalizedAsset.cs:197
    17.   at DialogueManager.LoadTextAssets () [0x0017f] in C:\gamedev\unity\monospaced-lovers\Assets\Scripts\Singletons\DialogueManager.cs:354
    18.   at GameController+<DoAsyncLoad>d__93.MoveNext () [0x00143] in C:\gamedev\unity\monospaced-lovers\Assets\Scripts\Singletons\GameController.cs:376
    19.   at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00020] in C:\buildslave\unity\build\Runtime\Export\Scripting\Coroutines.cs:17

    My code looks something like this

    Code (CSharp):
    1. LocalizedTextAsset asset = new LocalizedTextAsset();
    2. Debug.Assert(asset != null, "LocalizedTextAsset is null. Perhaps the localization library hasn't initialized yet?");
    3.  
    4. asset.TableEntryReference = str;
    5. asset.TableReference = "Human NPCs";
    6.  
    7. //print("Trying to load " + asset.TableEntryReference.Key + " from table " + asset.TableReference.TableCollectionName + " on frame " + Time.frameCount);
    8. AsyncOperationHandle<TextAsset> handle = asset.LoadAssetAsync();
    9. Debug.Assert(handle.IsValid(), "Load text asset async handle is null");
    10.  
    11. handle.Completed += (reference) => OnAsyncLoad(reference);
    The line with the "asset.LoadAssetAsync();" is the one that throws the error. The asserts haven't managed to catch anything yet; the only error in the console is the null ref error.

    I tried deleting my Addressables cache and rebuilding, but no dice. Anyone know what this error is about?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Can you please file a bug report so we can look into it?
     
  3. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    You mean from Help -> Report a Bug in the Unity editor? That will be difficult because I'd have to include my whole project; not sure if I could reproduce this in a fresh project without all of the assets.

    I'm getting a different error now, anyway. The Addressables Analyzer "fixed" the problem in my first post, but now I can't rebuild Addressables at all - I'm getting a "The given key was not present in the dictionary" error.

    Unfortunately it doesn't say which key is missing, and I can't add a debug line; the file "BuildScriptBase.cs" is part of the Addressables package, so if I try to edit it, it reverts back to the source.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    I saw someone fix that by deleting the Addressable folder in the project and then running the 3 Analyzers to re add everything.
     
    _eternal likes this.
  5. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    Thanks for the tip - that did the trick. Basically I removed the whole AddressableAssetsData folder and then re-added everything. The analyzers took care of the localization files, but my other files had to be manually placed back into their original groups (not a big deal at my scale).
     
    karl_jones likes this.