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

Dynamic updating of LocalizedString in script does not update the TMP text for the update event

Discussion in 'Localization Tools' started by DallasP9124, Feb 8, 2022.

  1. DallasP9124

    DallasP9124

    Joined:
    Jul 15, 2020
    Posts:
    11
    I have a game object with a Localized String Event component. I assigned a Smart string reference to that component. I create a component of my own that will update that Localized String with a value for the variable in the smart string using the Arguments property of the Localized String. There is another GameObject with the TMP Text component that is meant to display the result of the string and I assign that TMP Text to the LSE's Update String event.

    There are two things I need to ask about.
    First, when I have Local Variables set with a default value for the variable of the Smart string, that is the only value that is ever seen on the TMP Text. In my script that updates the value, the updated string is never set to the TMP Text even though the value is compiled correctly with the provided arguments.

    Second, is it a bug if I have a Smart string assigned to a LSE and don't have a Local Variable defined as a 'default' and for that setup to cause a FormattingException occur in the editor? It would seem to me that the package would be smart enough to know if the value is available or not and just evaluate to an empty string.

    example: FormattingException: Error parsing format string: Could not evaluate the selector

    In short, is it true that Localized String Event components with a string assignment from a string table should be updatable in a script and also fire update events for any assigned component in the Update String section in the editor?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    I'm not entirely sure I understand. Is it that you are changing the LocalizedString.Arguments and the string does not automatically update? Changing the Arguments does not currently cause an automatic update, you need to call RefreshString. If you feel it should cause an automatic update you can file a bug report and we can consider it.

    This is by design as a missing argument is considered a bug. You can change this in the Localization Settings. Setting Ignore should replace them with an empty string.
    upload_2022-2-8_11-10-59.png
     
  3. DallasP9124

    DallasP9124

    Joined:
    Jul 15, 2020
    Posts:
    11
    I do indeed change the arguments and call on refresh string. The issue is that the resulting string is correct based on what is generated but the TMP object that is listening to the change event does not get updated.

    This is the update code:
    Code (CSharp):
    1.  
    2. private void UpdatePointString()
    3. {
    4.     var dict = new Dictionary<string, int> {{"points", _availablePoints}};
    5.     pointString.StringReference.Arguments = new object[] {dict};
    6.     pointString.StringReference.RefreshString();
    7. }
    8.  
    This is the TMP_Text object with the LocalizedString configuration:
    upload_2022-2-15_9-11-40.png

    And this is my component that takes the reference of that localized string that is being updated in the code above. I would expect that the text would be updated since I am updating the localized string.
    upload_2022-2-15_9-13-16.png

    Is this setup incorrect for what I am trying to achieve? The documentation made it seem very easy but thinking that there is a bug if this is correct but the TMP does not get updated.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    I think this will cause problems
    Untitled.png

    You have 2 conflicting sources of data called "points". So it's likely picking the one with the 0 value. Try removing this variable or updating it instead of using the Arguments and Dictionary.

    E.G
    Code (csharp):
    1. (pointString.StringReference["points"] as IntVariable).Value = _availablePoints;
    Does that fix the issue?
     
  5. DallasP9124

    DallasP9124

    Joined:
    Jul 15, 2020
    Posts:
    11
    Indeed the changing of the settings to ignore and removing the local variable did help. And that last snippet will help with default work in the future. Thank you for helping me traverse this.
     
    JadsonAlmeida and karl_jones like this.