Version: Unity 6.5 Beta (6000.5)
Language : English
Auto sizing text elements
Panel Text Settings assets

Set language direction

You can use the language-direction (LanguageDirection) attribute to set the text direction for visual elementsA node of a visual tree that instantiates or derives from the C# VisualElement class. You can style the look, define the behaviour, and display it on screen as part of the UI. More info
See in Glossary
, 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:

  • Inherited (default): The element inherits the text direction from its parent.
  • LTR (Left-to-Right): Forces the text within the element to flow from left to right.
  • RTL (Right-to-Left): Forces the text within the element to flow from right to left.

You can set the language direction in UI Builder, UXML, or C# scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary
.

In UI Builder

  1. Select the visual element you want to modify.
  2. In the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
    See in Glossary
    panel, expand Attributes.
  3. From the Language Direction dropdown, select the desired direction.

In UXML

To set the language direction in UXML, use the language-direction attribute. For example:

<Label text="Hello" language-direction="RTL" />

In C# scripts

To set the language direction in C# scripts, use the LanguageDirection property. For example:

new TextElement() {languageDirection = LanguageDirection.RTL};

Cursor movement in bidirectional text

In text input fieldsA field that allows the user to input a Text string More info
See in Glossary
, cursor movement through bidirectional (BIDI) text depends on how the caret advances through logical character order versus visual order on screen.

Logical cursor movement

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.

Logical cursor movement example
Logical cursor movement example

Visual cursor movement

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.

Additional resources

Auto sizing text elements
Panel Text Settings assets