You can use the language-direction (LanguageDirection) attribute to set the text direction for visual elements, specifically whether it flows from left to right (LTR) or right to left (RTL). This is important for languages such as Arabic and Hebrew, which users read from right to left. This attribute corresponds to the dir property in HTML and cascades to child elements.
Language direction can impact the text layout behaviors, such as the position of ellipses and punctuation.
Language direction supports the following values:
You can set the language direction in UI Builder, UXML, or C# scripts.
To set the language direction in UXML, use the language-direction attribute. For example:
<Label text="Hello" language-direction="RTL" />
To set the language direction in C# scripts, use the LanguageDirection property. For example:
new TextElement() {languageDirection = LanguageDirection.RTL};
In text input fields, cursor movement through bidirectional (BIDI) text depends on how the caret advances through logical character order versus visual order on screen.
Unity uses logical cursor movement. The cursor moves through BIDI text according to the direction of each text segment. For example, when you press the Left Arrow in a sentence that mixes Arabic and English, the caret moves right-to-left through the Arabic portion, then jumps at the leftmost character of the English segment and continues left-to-right until it reaches the end of that segment.
Some applications use visual cursor movement, where the caret moves to the next visual character regardless of segment direction. That behavior can feel more intuitive in some cases, but Unity does not use this model for UI Toolkit text fields.