Thai, Lao, Khmer and Myanmar Line Breaking in Unity
Last reviewed
Thai, Lao, Khmer and Myanmar are written without spaces between words, so a line can only break where a dictionary says one word ends and the next begins. TextMesh Pro has no word segmentation: it breaks lines only at spaces, zero-width spaces and hyphens, so a Thai line is cut in the middle of a word wherever it overflows.
UniText ships word-segmentation dictionaries for Thai, Lao, Khmer and Myanmar. Add the ones for the languages you ship in Project Settings, and lines break between words while HarfBuzz stacks vowel and tone marks correctly.
Why Thai lines break in the wrong place
The Unicode line-breaking rules (UAX #14) give Thai, Lao, Khmer and Myanmar characters a class of their own: break opportunities inside them are not defined by the characters themselves and have to come from a dictionary of words. A renderer that only breaks at spaces sees a whole Thai sentence as one long word.
A common workaround is to run the text through a segmentation tool and insert invisible zero-width spaces between words, which TextMesh Pro does treat as break opportunities. Tools such as ThaiTextCare do this with a dictionary and also fix overlapping tone marks. It works, but every string has to pass through the tool, including translation updates and text the game builds at runtime, such as names and chat, and each language needs its own tool.
The same scripts also stack vowel signs and tone marks above and below consonants. Placing those marks is the job of a shaping engine, which reads the positions from the font's OpenType tables.
How UniText breaks Thai, Lao, Khmer and Myanmar
- Open
Project Settings › LightSide › UniText › Word Segmentation. - Add the dictionaries for the languages your game ships. The package includes ready dictionaries for Thai, Lao, Khmer and Myanmar.
- Lines in those scripts now break at word boundaries in every UniText component, for static and runtime text alike.
Each dictionary adds to the build, which is why none is enabled by default: a game that ships only Thai adds only the Thai dictionary. The Dictionary Builder tab in Tools › LightSide › UniText › Utilities builds a dictionary of your own, for example one that includes your game's character and place names.
- Word boundaries also drive word selection, caret navigation by word and word-by-word animation.
- HarfBuzz positions stacked vowel signs and tone marks from the font's OpenType tables.
- Chinese and Japanese break lines between characters without a dictionary. A CJK dictionary is used only for word selection, navigation and word-by-word animation.
- On desktop and mobile, system fonts render Thai, Lao, Khmer and Myanmar without shipping a font. WebGL needs a font assigned for each script.
Questions
Do I need to insert zero-width spaces into my translations?
What about words the dictionary does not know?
Does Khmer coeng stacking work?
Check it in your project
Run the browser demo, follow the setup guide, or compare the free version with the licenses.
Related problems
- Hindi and Indic Scripts in Unity: Fix Broken Conjuncts and Vowel SignsTextMesh Pro does no Indic shaping, so Devanagari, Tamil and Bengali render with broken conjuncts and misplaced vowel signs. UniText shapes every Indic script with HarfBuzz using the font’s own rules.
- Unity Text Shows Squares Instead of Characters: Font Fallback That Just WorksSquares appear when no font in the fallback chain has the character. UniText falls back to the operating system’s fonts per language automatically, so any language renders without shipping a font for it.
- TextMeshPro Alternative for Unity: UniText vs TMP vs UI ToolkitUniText replaces TextMesh Pro with a HarfBuzz-based text engine: shaping for Arabic and Indic scripts, Unicode BiDi, emoji sequences, variable fonts and system-font fallback on uGUI and in world space.
