Unity version 6 (6000.0.23f1, LTS). I just updated from the previous version to this one. When I exit play mode in my game, or when I make any changes in the UI Builder, I get three errors:
System.Exception: SelectedLocale is null. Database could not get table.
UnityEngine.Localization.Settings.LocalizedStringDatabase:GetLocalizedString (UnityEngine.Localization.Tables.TableEntryReference,UnityEngine.Localization.Locale,UnityEngine.Localization.Settings.FallbackBehavior,object[])
LocalizedTextUI:<.ctor>b__2_0 () (at Assets/Scripts/UI/LocalizedTextUI.cs:18)
UnityEngine.UIElements.UIElementsRuntimeUtilityNative:UpdatePanels ()
OperationException : SelectedLocale is null. Could not get table entry.
UnityEngine.Localization.Settings.LocalizedStringDatabase:GetLocalizedString (UnityEngine.Localization.Tables.TableEntryReference,UnityEngine.Localization.Locale,UnityEngine.Localization.Settings.FallbackBehavior,object[])
LocalizedTextUI:<.ctor>b__2_0 () (at Assets/Scripts/UI/LocalizedTextUI.cs:18)
UnityEngine.UIElements.UIElementsRuntimeUtilityNative:UpdatePanels ()
OperationException : SelectedLocale is null. Could not get localized string.
UnityEngine.Localization.Settings.LocalizedStringDatabase:GetLocalizedString (UnityEngine.Localization.Tables.TableEntryReference,UnityEngine.Localization.Locale,UnityEngine.Localization.Settings.FallbackBehavior,object[])
LocalizedTextUI:<.ctor>b__2_0 () (at Assets/Scripts/UI/LocalizedTextUI.cs:18)
UnityEngine.UIElements.UIElementsRuntimeUtilityNative:UpdatePanels ()
The localization on my text still works as expected. I have one localization table called main(StringTable). The selected collection is main(StringTable)(StringTable). I only have a string database, not an asset database.
My localization settings:
I’m using the UI Toolkit. My UI has just one instance of LocalizedTextUI. Here is that script:
using UnityEngine;
using UnityEngine.Localization.Settings;
using UnityEngine.UIElements;
[UxmlElement]
public partial class LocalizedTextUI : TextElement
{
public static BindingId keyProperty = nameof(key);
[UxmlAttribute]
public string key;
public LocalizedTextUI()
{
this.schedule.Execute(() => {
if (!string.IsNullOrEmpty(key))
{
string loc = LocalizationSettings.StringDatabase.GetLocalizedString(key);
if (!string.IsNullOrEmpty(loc))
{
text = loc;
return;
}
if (Application.isPlaying)
{
Debug.LogWarning("Text has no localized string");
}
text = key;
}
});
}
}
