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. Dismiss Notice

Question Force re-initialization / Refresh LocalStringEvents after patching string tables.

Discussion in 'Localization Tools' started by MrKettle, Sep 28, 2023.

  1. MrKettle

    MrKettle

    Joined:
    Jun 11, 2018
    Posts:
    7
    Hi

    I have a simple code for patching StringTables from local CSV-files. CSV is imported and we replace matching keys/strings in the table when the app starts (SubsystemRegistration).

    The patching works, LocalizationTable editor window shows the patched strings, but nothing is updated on screen before changing languages.

    What I want is to have all LocalizedStringEvents update their string when the patching is done.

    I've searched a bit on the forums, but I haven't found a working solution for my case. LocalizationSettings.InitializationOperation doesn't seem to do anything.

    I've even tried getting all LocalizedStringEvents and refreshing them, but then I get a nullref exception in the DetailedLocalizationTable.cs at
    Code (CSharp):
    1.    /// <summary>
    2.         /// Returns true if any tag metadata of type TShared contains this entry.
    3.         /// </summary>
    4.         /// <typeparam name="TShared"></typeparam>
    5.         /// <returns></returns>
    6.         public bool HasTagMetadata<TShared>() where TShared : SharedTableEntryMetadata
    7.         {
    8.             var tag = Table.GetMetadata<TShared>();
    9.             return tag?.IsRegistered(this) == true;
    10.         }

    Note: Currently I'm not copying over the KeyID (just the key).KeyID is 0 in patched entrees.

    Anyone that some tips or experience to share? Thanks in advance.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    MrKettle likes this.
  3. MrKettle

    MrKettle

    Joined:
    Jun 11, 2018
    Posts:
    7
    ITableProcessor did the trick. I modified my code to fit with the post processor logic, and registered it on SubsystemRegistration. Thanks for swift reply @karl_jones!
     
    karl_jones likes this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    That's great. It's actually a serialized field so you should be able to register it in the editor and not have to do it in the player, although if it's working as is then no problem :)
     
    MrKettle likes this.
  5. MrKettle

    MrKettle

    Joined:
    Jun 11, 2018
    Posts:
    7
    I'll keep that in mind if I bump into issues when I try to build

    I think its better do it in code like this, instead of some unseen reference, since there's no Editor UI showing what post processors are assigned.
     
    Last edited: Sep 28, 2023
    karl_jones likes this.
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    That's a good point, we should add a UI for it. I'll add it to our tasks.
     
    MrKettle likes this.
  7. MrKettle

    MrKettle

    Joined:
    Jun 11, 2018
    Posts:
    7
    For sure. After doing some refactoring, Unity still has a reference to an older table processor.
    upload_2023-9-29_12-56-22.png

    I tried fixing it by by:
    Code (CSharp):
    1.     [MenuItem("Tools/Localization/Clear PostProcessors")]
    2.     public static void ClearPostProcessors()
    3.     {
    4.         var settings = LocalizationEditorSettings.ActiveLocalizationSettings;
    5.         settings.GetStringDatabase().TablePostprocessor = null;
    6.         settings.GetAssetDatabase().TablePostprocessor = null;
    7.  
    8.         // Set dirty so the changes are saved.
    9.         EditorUtility.SetDirty(settings);
    10.     }
    but the warning won't go away.

    - How should we clear PostProcessors?
    - Also: if we set "Preload All Locales", will that mean that my Processor/Patcher will run on all tables and locales on initialization? Trying to figure out how to carry out the patching once at startup.
     

    Attached Files:

  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Try setting the localization settings dirty after making a change. EditorUtility.SetDirty(LocalizationSettings
    instance)

    Preload all locales will load them all and let you do all tables but I would not recommend it. Your table post processor will always be run after loading a table so it should be safe to just patch the tables as they are loaded.
     
  9. MrKettle

    MrKettle

    Joined:
    Jun 11, 2018
    Posts:
    7
    Thanks for the swift reply. That yielded some result, but now I'm getting these errors:
    upload_2023-9-29_14-28-7.png

    Restarting Editor did not help. I'm guessing this is an Editor-only error, but still a little annoying. Any ideas?
     
  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    I'm not familiar with those errors. Can you share the editor log file? Does it happen all the time?
    What does the code look like?
     
  11. MrKettle

    MrKettle

    Joined:
    Jun 11, 2018
    Posts:
    7
    Sure.

    Log: https://pastebin.com/2bJK6N4G

    The errors came after I did this:
    Code (CSharp):
    1.  
    2.         var settings = LocalizationEditorSettings.ActiveLocalizationSettings;
    3.         settings.GetStringDatabase().TablePostprocessor = null;
    4.         settings.GetAssetDatabase().TablePostprocessor = null;
    5.  
    6.         // Set dirty so the changes are saved.
    7.         EditorUtility.SetDirty(LocalizationSettings.Instance);
    8.  
    I think the GC error came after my previous attempt which I posted above; same, but with different param for the SetDirty.
     
  12. MrKettle

    MrKettle

    Joined:
    Jun 11, 2018
    Posts:
    7
    So I made a new project and copied the scripts over. Same errors appeared even before pressing play, so I guess there's something else going on. Unity 2022.3.10f1