Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

SmartSettings NullReferenceException

Discussion in 'Localization Tools' started by speppers, Jan 19, 2021.

  1. speppers

    speppers

    Joined:
    Jun 18, 2018
    Posts:
    8
    I'm getting the following error where it appears the SmartSettings object is null in LiteralText.toString(). Using version 0.9.

    Code looks like:
    Code (CSharp):
    1.  
    2.     public LocalizedString TimeString;
    3.     public string TimeNow => "5 Hours";
    4.  
    5.     private void OnEnable()
    6.     {
    7.         TimeString.Arguments = new[] { this };
    8.         TimeString.StringChanged += OnTimeStringChange;
    9.     }
    10.  
    11.     private void OnDisable()
    12.     {
    13.         TimeString.StringChanged -= OnTimeStringChange;
    14.     }
    Errors on the TimeString.StringChanged += OnTimeStringChange part.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Localization.SmartFormat.Core.Parsing.LiteralText.ToString () (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Smart Format/Core/Parsing/LiteralText.cs:23)
    3. UnityEngine.Localization.SmartFormat.SmartFormatter.Format (UnityEngine.Localization.SmartFormat.Core.Formatting.FormattingInfo formattingInfo) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Smart Format/SmartFormatter.cs:233)
    4. UnityEngine.Localization.SmartFormat.SmartFormatter.Format (UnityEngine.Localization.SmartFormat.Core.Formatting.FormatDetails formatDetails, UnityEngine.Localization.SmartFormat.Core.Parsing.Format format, System.Object current) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Smart Format/SmartFormatter.cs:218)
    5. UnityEngine.Localization.SmartFormat.SmartFormatter.FormatWithCache (UnityEngine.Localization.SmartFormat.Core.Formatting.FormatCache& cache, System.String format, System.Object[] args) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Smart Format/SmartFormatter.cs:193)
    6. UnityEngine.Localization.Tables.StringTableEntry.GetLocalizedString (System.Object[] args) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Tables/StringTable.cs:94)
    7. UnityEngine.Localization.Settings.LocalizedStringDatabase.GetLocalizedStringProcessTableEntry (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] entryOp, UnityEngine.Localization.Tables.TableEntryReference tableEntryReference, UnityEngine.Localization.Locale locale, System.Object[] arguments) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Settings/Database/LocalizedStringDatabase.cs:197)
    8. UnityEngine.Localization.LocalizedString.RefreshString () (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Localized Reference/LocalizedString.cs:138)
    9. UnityEngine.Localization.LocalizedString.AutomaticLoadingCompleted (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject] loadOperation) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Localized Reference/LocalizedString.cs:232)
    10. UnityEngine.Localization.LocalizedString.HandleLocaleChange (UnityEngine.Localization.Locale _) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Localized Reference/LocalizedString.cs:220)
    11. UnityEngine.Localization.LocalizedString.ForceUpdate () (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Localized Reference/LocalizedString.cs:203)
    12. UnityEngine.Localization.LocalizedString.add_StringChanged (UnityEngine.Localization.LocalizedString+ChangeHandler value) (at Library/PackageCache/com.unity.localization@0.9.0-preview/Runtime/Localized Reference/LocalizedString.cs:98)
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    Thats strange. Could you show a screenshot of your smart settings(Localization Settings/String Database) and the string that is being parsed?
     
  3. speppers

    speppers

    Joined:
    Jun 18, 2018
    Posts:
    8
    Looks like its probably the same issue as this https://forum.unity.com/threads/nre-with-list-formatting.985803/. Happens only if I toggle the smart checkbox. Once checked, even if the string is empty, even hitting the preview button in the LocalizedStringEvent UI triggers the error in the editor. I've had to work around this by keeping the smart checkbox disabled and manually using Smart.Format myself which isn't ideal. I'm using Unity 2020.2.1 but also noticed it on 2019.18 LTS. Mac OS.
     
  4. speppers

    speppers

    Joined:
    Jun 18, 2018
    Posts:
    8
    Here's a screenshot of my String Database settings.
     

    Attached Files:

  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    It looks like your settings may be corrupt.
    INVALID_UTF8_STRING looks wrong.

    Can you file a bug report?
     
  6. speppers

    speppers

    Joined:
    Jun 18, 2018
    Posts:
    8
    Yeah just filed one. Do you know what that setting should be?
     
  7. speppers

    speppers

    Joined:
    Jun 18, 2018
    Posts:
    8
    So I was able to fix the issue by just deleting and recreating the LocalizationSettings asset.
     
    karl_jones likes this.
  8. B_Richard

    B_Richard

    Joined:
    Sep 21, 2020
    Posts:
    16
    I had the same issue, it may have been caused when I updated Localization from version 0.8.x to 0.9.0.
    And like speppers, I had the INVALID_UTF8_STRING operator and it was fixed by recreating the LocalizationSettings asset from scratch.
     
    karl_jones likes this.