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:
NullReferenceException
at (wrapper managed-to-native) UnityEngine.Object.GetName(UnityEngine.Object)
at UnityEngine.Object.get_name () [0x00001] in C:\buildslave\unity\build\Runtime\Export\Scripting\UnityEngineObject.bindings.cs:194
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
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
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
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
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
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
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
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
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
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
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
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
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
at DialogueManager.LoadTextAssets () [0x0017f] in C:\gamedev\unity\monospaced-lovers\Assets\Scripts\Singletons\DialogueManager.cs:354
at GameController+<DoAsyncLoad>d__93.MoveNext () [0x00143] in C:\gamedev\unity\monospaced-lovers\Assets\Scripts\Singletons\GameController.cs:376
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
LocalizedTextAsset asset = new LocalizedTextAsset();
Debug.Assert(asset != null, "LocalizedTextAsset is null. Perhaps the localization library hasn't initialized yet?");
asset.TableEntryReference = str;
asset.TableReference = "Human NPCs";
//print("Trying to load " + asset.TableEntryReference.Key + " from table " + asset.TableReference.TableCollectionName + " on frame " + Time.frameCount);
AsyncOperationHandle<TextAsset> handle = asset.LoadAssetAsync();
Debug.Assert(handle.IsValid(), "Load text asset async handle is null");
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?
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.
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).