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?
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.
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:
private void UpdatePointString()
{
var dict = new Dictionary<string, int> {{"points", _availablePoints}};
pointString.StringReference.Arguments = new object[] {dict};
pointString.StringReference.RefreshString();
}
This is the TMP_Text object with the LocalizedString configuration:
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.
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.
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
(pointString.StringReference["points"] as IntVariable).Value = _availablePoints;
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.