Hello,
I’m currently trying to bind Smart Strings using the UITK Binding system. But I have this error if my localized string has more than one parameter :
FormattingException: Error parsing format string: Could not evaluate the selector "commander" at 15
Army of "{0}" ({commander})
I tried many things:
- renaming “{comander}” to “{1}”
- adding escape characters before parenthesis
- applying variables before binding the final localization
Nothing worked and the UI Builder crashes instantly when I apply the binding.
Here is my bindings before I apply (and UIBuilder crashed):
And this is what I got in UXML after clicking “Add binding”
<engine:Label text="Army of "Major Leader" (Le Cid)" name="ArmyName" class="title-block">
<Bindings>
<UnityEngine.Localization.LocalizedString property="text" table="GUID:b9b66f0c3558f2b4699028bbe23ba23c" entry="Id(10332677402736)">
<variables>
<UnityEngine.Localization.LocalVariable name="ArmyName" text="Army of "Major Leader" (Le Cid)" class="title-block">
<UnityEngine.Localization.SmartFormat.PersistentVariables.StringVariable value="Major Leader" />
</UnityEngine.Localization.LocalVariable>
<UnityEngine.Localization.LocalVariable name="ArmyName" text="Army of "Major Leader" (Le Cid)" class="title-block">
<UnityEngine.Localization.SmartFormat.PersistentVariables.StringVariable value="Le Cid" />
</UnityEngine.Localization.LocalVariable>
</variables>
</UnityEngine.Localization.LocalizedString>
</Bindings>
</engine:Label>
The UXML doesnt seem to match the screenshot. It looks like both your variables are named ArmyName and contain unexpected attributes (text & class).
Did you write the UXML by hand or was this generated by the UI Builder?
The format should be like this UI Toolkit (Unity 6+) | Localization | 1.5.4
I could totally make a GIF or a video if you want to.
What I am doing is exactly:
- right click on the “text” property on my label in UI Builder
- click “Add binding…”
- choose in “Type” > “UnityEngine.Localization/Localized String”
- click “Select Entry…”
- choose my localized string “Army of {0} ({commander})”
- unfold “Variables” collapsible
- add two “String” entries
- rename the first one “0” and the second one “commander”
- click “Add Binding”
- Ctrl+S my modification in UI Builder
- UI Builder turns black and the error infinitely throws in the Console
It sounds like a bug. Could you please file a bug report so we can look into it?
https://unity3d.com/unity/qa/bug-reporting
When I tried to reproduce the bug in an empty projet, I found that the bug is due to the fact that the Label has a name. It applies the name of the VisualElement to the bindings names (that’s why in the UXML I previously sent, bindings and label has the same name “ArmyName”)
1 Like
Do you have a bug number? Ill try and take a look at it
Yes, the ticket is IN-97002
1 Like
For a complete unknown reason, adding a localized binding on a VisualElement which has a name duplicate its property into the variables.
Here is the UXML code I got when I bind a localization with one variable on my Label:
<engine:Label text="Label" tooltip="tooltip text" tabindex="999" focusable="true" selectable="true" name="LabelName" class="my-custom-class">
<Bindings>
<UnityEngine.Localization.LocalizedString property="text" table="GUID:c50b2ca8126b2f1409b5535d3cb8d92c" entry="Id(5164298240)">
<variables>
<UnityEngine.Localization.LocalVariable name="LabelName" text="Label" tooltip="tooltip text" tabindex="999" focusable="true" selectable="true" class="my-custom-class">
<UnityEngine.Localization.SmartFormat.PersistentVariables.StringVariable value="variable text" />
</UnityEngine.Localization.LocalVariable>
</variables>
</UnityEngine.Localization.LocalizedString>
</Bindings>
</engine:Label>
Hey I just took a look at your bug report. It seems different that this thread. The issue in the bug report is about the spamming of the format error which is mainly down to the UI Builder updating every time you change something. We can ease this by making those name fields delayed so they dont fire as many change events. The name of the element doesnt have any impact though and im not seeing the corrupted UXML that you have provided. Is there some other steps I need to follow to reproduce that?
Could you make a gif/video showing how to reproduce it?
In the attached GIF, you can see that, after clicking “Add binding”, it seems to work but when I press Ctrl+S to save, my UI Builder freezes. And when I go to the UXML file, you can see that variables have the same name than my label

OK now I can reproduce it. Thanks!
1 Like