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 GameObjectLocalizer doesn't update when global variable is updated

Discussion in 'Localization Tools' started by hrkm, Jun 7, 2023.

  1. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    Hi, I've started using the localization package and for static strings it works great. My flow is:
    1. add TextMeshPro
    2. right click the text property in inspector, select "Localize Property" - this adds GameObjectLocalizer to the component lists
    3. configure the component to point out to the table and string to be used for the localization

    VOILA: the string gets properly picked out from the translation table.

    However, I recently added one with Smart String via global variable configured in the Localization preferences of my game project. The string is simply "Set {global.setNumber}" and the variable type is IntVariable.

    In code I use
    Code (CSharp):
    1.  
    2.        var source = LocalizationSettings.StringDatabase.SmartFormatter.GetSourceExtension<PersistentVariablesSource>();
    3.         IntVariable localizedSetTitleVariable = source["global"]["setNumber"] as IntVariable;
    4.         localizedSetTitleVariable.Value = _currentSet + 1;
    5.  
    What ends up happening is that on first scene load the string gets updated properly to say e.g. "Set 1" (assuming _currentSet=0), but then when I click a button to change that variable to say _currentSet=1, and invoke the same code as above the string in TextMeshPro still shows "Set 1", not "Set 2" as expected. I looked up the global variables object in my assets and it correctly says that "setNumber" is equal to 2, but the string does not update. Navigating out of scene and back to it causes the string to be recalculated and updates to new value, changing locale to another language also works.

    So it is essentially missing a responsiveness to an update of the underlying global variable.

    I replaced the GameObjectLocalizer with LocalizeStringEvent, pointed to the same localization string that uses that global variable and pointed it to the TextMeshPro.text property to update, and it updates every single time the above code is being called with a new value of _currentSet.

    What am I missing with using GameObjectLocalizer to achieve the same effect?

    Things I tried:
    - wrapping things in PersistentVariablesSource.UpdateScope (or equivalent begin/end pair)
    - setting update type to full (instead of default partial)


    I also noticed that regardless of which method I use the first string loading takes a bit of a time, there's a visible delay, but that's a separate bug/question I suppose. :)
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
  3. hrkm

    hrkm

    Joined:
    Oct 21, 2013
    Posts:
    13
    Ah, ok, can you please let me know how I can submit the bug report? I'll do that when I get back home. :)

    And yes, it looks like table load time - if I start from a different scene and navigate for the first time to the one with global variable the string is already there with the value of the global variable as expected. (and this all was in Unity Editor experience, not an actual on device build)
     
  4. Off_the_leash

    Off_the_leash

    Joined:
    Feb 5, 2018
    Posts:
    8
    Hello @karl_jones :),
    could you please try to fix it the issues with files outside of the "Assembly-CSharp" for the Custom Persistent Variables?
    I'm tried using it outside of the root of the assembly and I'm start gets error like: "Missing types referenced from component...", Assembly-CSharp (1 object)
    Meanwhile it's works for me only with the main assembly.
    By the way, when I'm change the namespace for these variables I get all the data in the inspector as broken.
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    I'm not sure what you mean. Can you please file a bug report, it's not something I am aware of.