Search Unity

LocalizedStringEvent not triggering UpdateString when local variable value changes

Discussion in 'Localization Tools' started by travlake, Dec 16, 2021.

  1. travlake

    travlake

    Joined:
    Oct 4, 2019
    Posts:
    50
    I have a UI object with a TMP component, LocalizedStringEvent component, and a very simple "TestDataComponent":

    Code (CSharp):
    1. public class TestDataComponent : MonoBehaviour
    2. {
    3.     public int myInt;
    4. }
    5.  
    The LocalizedStringEvent uses the TestDataComponent as a local variable named "test-component", and the string entry is simply "{test-component.myInt}"



    This all works in the sense that the TMP component shows the value of myInt, as it's supposed to.

    The part that doesn't work as I expected is that if the value of myInt changes, either by me in the inspector or via another script, the TMP object doesn't update and the LocalizedStringEvent doesn't call UpdateString().

    How do I make the TMP component update, ideally both in editor and play mode, whenever the value of myInt changes?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    The automatic updates are triggered when a persistent variable changes. In this case you are not changing the persistent variable but changing the property inside of the persistent variable (myInt), we have no way to detect this.
    You could use an int variable instead of an object one, this would then trigger the update. Alternatively you could call RefreshString inside of the my int setter method or somewhere else when the value is changing.
     
    travlake likes this.
  3. travlake

    travlake

    Joined:
    Oct 4, 2019
    Posts:
    50
    Cool, thanks!
     
  4. travlake

    travlake

    Joined:
    Oct 4, 2019
    Posts:
    50
    One more question for you, @karl_jones (I figured it's not worth a new thread)

    Is there any way to alphabetize (or otherwise change the order of) the list of String Table Collections that appears in the Inspector?

    Right now it looks like the attached for me.
     

    Attached Files:

  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    In the next release 1.1 we have integrated Unity Search as an alternative to this selector which does let you sort the list and use several new filters. Should be out early January.
     
    travlake likes this.
  6. swedajan

    swedajan

    Joined:
    Jan 12, 2021
    Posts:
    3
    Very cool, looking forward to that addition.
     
    karl_jones likes this.