Skjalg
March 3, 2021, 10:19pm
1
If I click on the checkbox in a localization table that says “Smart” I get this error.
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Localization.SmartFormat.Core.Parsing.Parser.ParseFormat (System.String format, System.Collections.Generic.List`1[T] formatterExtensionNames) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Smart Format/Core/Parsing/Parser.cs:437)
UnityEngine.Localization.SmartFormat.SmartFormatter.Format (System.IFormatProvider provider, System.String format, System.Object[ ] args) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Smart Format/SmartFormatter.cs:168)
UnityEngine.Localization.SmartFormat.SmartFormatter.Format (System.String format, System.Object[ ] args) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Smart Format/SmartFormatter.cs:153)
UnityEngine.Localization.Settings.LocalizedStringDatabase.ProcessUntranslatedText (System.String key, System.Int64 KeyId, UnityEngine.Localization.Tables.TableReference tableReference, UnityEngine.Localization.Tables.StringTable table, UnityEngine.Localization.Locale locale) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Settings/Database/LocalizedStringDatabase.cs:188)
UnityEngine.Localization.Settings.LocalizedStringDatabase.GenerateLocalizedString (UnityEngine.Localization.Tables.StringTable table, UnityEngine.Localization.Tables.StringTableEntry entry, UnityEngine.Localization.Tables.TableReference tableReference, UnityEngine.Localization.Tables.TableEntryReference tableEntryReference, UnityEngine.Localization.Locale locale, System.Object[ ] arguments) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Settings/Database/LocalizedStringDatabase.cs:117)
UnityEngine.Localization.LocalizedString.RefreshString () (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Localized Reference/LocalizedString.cs:159)
UnityEngine.Localization.LocalizedString.AutomaticLoadingCompleted (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] loadOperation) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Localized Reference/LocalizedString.cs:296)
UnityEngine.Localization.LocalizedString.HandleLocaleChange (UnityEngine.Localization.Locale _) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Localized Reference/LocalizedString.cs:284)
UnityEngine.Localization.LocalizedString.ForceUpdate () (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Localized Reference/LocalizedString.cs:218)
UnityEngine.Localization.LocalizedString.add_StringChanged (UnityEngine.Localization.LocalizedString+ChangeHandler value) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Localized Reference/LocalizedString.cs:116)
UnityEngine.Localization.Components.LocalizeStringEvent.RegisterChangeHandler () (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Component Localizers/LocalizeStringEvent.cs:107)
UnityEngine.Localization.Components.LocalizeStringEvent.OnEnable () (at Library/PackageCache/com.unity.localization@0.10.0-preview/Runtime/Component Localizers/LocalizeStringEvent.cs:87)```
Is there some kind of setup I am missing?
That seems to indicate that the Settings are null in the Parser. Its a serialised field that should not be null.
What happens if you look at the settings in the inspector?
Can you see a value for this?
Can you share the Localization Settings.asset file ?
One way to fix this is to delete the Settings file and recreate it although it would be nice to figure out what actually caused this issue
Skjalg
March 3, 2021, 10:48pm
3
Here you go!
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a07b5cd0b1b829245bc8c4b6978793e8, type: 3}
m_Name: Localization Settings
m_EditorClassIdentifier:
m_StartupSelectors:
- id: 0
- id: 1
- id: 2
m_AvailableLocales:
id: 3
m_AssetDatabase:
id: 4
m_StringDatabase:
id: 5
references:
version: 1
00000000:
type: {class: CommandLineLocaleSelector, ns: UnityEngine.Localization.Settings,
asm: Unity.Localization}
data:
m_CommandLineArgument: -language =
00000001:
type: {class: SystemLocaleSelector, ns: UnityEngine.Localization.Settings, asm: Unity.Localization}
data:
dummyObject: 0
00000002:
type: {class: SpecificLocaleSelector, ns: UnityEngine.Localization.Settings,
asm: Unity.Localization}
data:
m_LocaleId:
m_Code: en
00000003:
type: {class: LocalesProvider, ns: UnityEngine.Localization.Settings, asm: Unity.Localization}
data:
dummyObject: 0
00000004:
type: {class: LocalizedAssetDatabase, ns: UnityEngine.Localization.Settings,
asm: Unity.Localization}
data:
m_DefaultTableReference:
m_TableCollectionName: FakeLocaleTest
00000005:
type: {class: LocalizedStringDatabase, ns: UnityEngine.Localization.Settings,
asm: Unity.Localization}
data:
m_DefaultTableReference:
m_TableCollectionName: FakeLocaleTest
m_NoTranslationFoundFormat: '{0}'
m_SmartFormat:
id: 6
00000006:
type: {class: SmartFormatter, ns: UnityEngine.Localization.SmartFormat, asm: Unity.Localization}
data:
m_Settings:
id: 7
m_Parser:
id: 8
m_Sources:
- id: 9
- id: 10
- id: 11
- id: 12
- id: 13
m_Formatters:
- id: 14
- id: 14
- id: 14
- id: 14
- id: 14
- id: 14
- id: 14
- id: 14
00000007:
type: {class: SmartSettings, ns: UnityEngine.Localization.SmartFormat.Core.Settings,
asm: Unity.Localization}
data:
m_FormatErrorAction: 2
m_ParseErrorAction: 2
m_CaseSensitivity: 0
m_ConvertCharacterStringLiterals: 1
00000008:
type: {class: Parser, ns: UnityEngine.Localization.SmartFormat.Core.Parsing,
asm: Unity.Localization}
data:
m_OpeningBrace: 123
m_ClosingBrace: 125
m_Settings:
id: 14
m_AlphanumericSelectors: 7
m_AllowedSelectorChars: "\x02"
m_Operators: INVALID_UTF8_STRING
m_AlternativeEscaping: 0
m_AlternativeEscapeChar: 0
00000009:
type: {class: ListFormatter, ns: UnityEngine.Localization.SmartFormat.Extensions,
asm: Unity.Localization}
data:
m_Names:
- list
- l
-
m_SmartSettings:
id: 14
0000000A:
type: {class: DictionarySource, ns: UnityEngine.Localization.SmartFormat.Extensions,
asm: Unity.Localization}
data:
dummyObject: 0
0000000B:
type: {class: XmlSource, ns: UnityEngine.Localization.SmartFormat.Extensions,
asm: Unity.Localization}
data:
dummyObject: 0
0000000C:
type: {class: ReflectionSource, ns: UnityEngine.Localization.SmartFormat.Extensions,
asm: Unity.Localization}
data:
dummyObject: 0
0000000D:
type: {class: DefaultSource, ns: UnityEngine.Localization.SmartFormat.Extensions,
asm: Unity.Localization}
data:
dummyObject: 0
0000000E:
type: {class: , ns: , asm: }
Oh yeah it’s totally broken. All the formatters have gone and there’s a strange utf8 error. Any idea how you got into this situation? I suspect it’s a serializereference bug.
Delete the settings and creating a new one will fix it.
Skjalg
March 4, 2021, 9:21am
5
Yeah that fixed it thanks!
Just one thing though, adding a list formatter by using the + icon there produces an error
MissingMethodException: Default constructor not found for type UnityEngine.Localization.SmartFormat.Extensions.ListFormatter
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Activator.CreateInstance (System.Type type) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEditor.Localization.UI.Toolkit.ManagedReferenceReorderableList.AddManagedItem (UnityEditor.Localization.UI.Toolkit.ReorderableList list, System.Type type, System.Int32 index) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Editor/UI/Utility/ManagedReferenceReorderableList.cs:100)
UnityEditor.Localization.UI.Toolkit.ManagedReferenceReorderableList+<>c__DisplayClass12_1.<ShowAddItemMenu>b__0 () (at Library/PackageCache/com.unity.localization@0.10.0-preview/Editor/UI/Utility/ManagedReferenceReorderableList.cs:84)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at <208995a09fe148f5a6f6c571838c154f>:0)
Skjalg:
Yeah that fixed it thanks!
Just one thing though, adding a list formatter by using the + icon there produces an error
MissingMethodException: Default constructor not found for type UnityEngine.Localization.SmartFormat.Extensions.ListFormatter
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Activator.CreateInstance (System.Type type) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEditor.Localization.UI.Toolkit.ManagedReferenceReorderableList.AddManagedItem (UnityEditor.Localization.UI.Toolkit.ReorderableList list, System.Type type, System.Int32 index) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Editor/UI/Utility/ManagedReferenceReorderableList.cs:100)
UnityEditor.Localization.UI.Toolkit.ManagedReferenceReorderableList+<>c__DisplayClass12_1.<ShowAddItemMenu>b__0 () (at Library/PackageCache/com.unity.localization@0.10.0-preview/Editor/UI/Utility/ManagedReferenceReorderableList.cs:84)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at <208995a09fe148f5a6f6c571838c154f>:0)
Ah I actually just discovered that one myself. I created a bug report for it.
1 Like
Skjalg:
Yeah that fixed it thanks!
Just one thing though, adding a list formatter by using the + icon there produces an error
MissingMethodException: Default constructor not found for type UnityEngine.Localization.SmartFormat.Extensions.ListFormatter
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Activator.CreateInstance (System.Type type) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEditor.Localization.UI.Toolkit.ManagedReferenceReorderableList.AddManagedItem (UnityEditor.Localization.UI.Toolkit.ReorderableList list, System.Type type, System.Int32 index) (at Library/PackageCache/com.unity.localization@0.10.0-preview/Editor/UI/Utility/ManagedReferenceReorderableList.cs:100)
UnityEditor.Localization.UI.Toolkit.ManagedReferenceReorderableList+<>c__DisplayClass12_1.<ShowAddItemMenu>b__0 () (at Library/PackageCache/com.unity.localization@0.10.0-preview/Editor/UI/Utility/ManagedReferenceReorderableList.cs:84)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at <208995a09fe148f5a6f6c571838c154f>:0)
This is quite a simple fix so if you need a workaround it can be fixed by modifying the file:
com.unity.localization/Packages/com.unity.localization/Editor/UI/Smart Format/SmartFormatterPropertyField.cs
Add this to line 32
formatters.AddCallback = (l, i) => ShowAddMenu(l, i, property);