Skip to content

GetStream/unity-dynamic-font-fallback

Repository files navigation

TextMesh Pro Unicode Fallback Demo

A Unity demo showing how to support a wide range of Unicode characters in TextMesh Pro without bundling a massive “whole-world” font.

The project uses a hybrid font setup: a small static atlas for common characters, plus dynamic fallback fonts that generate missing glyphs only when they are actually used. This keeps the build small while still allowing users to type mixed-script text such as Latin, Greek, Cyrillic, CJK, Korean, Japanese, and symbols.

Dynamic font fallback demo — typing mixed scripts and watching fallback atlases populate in real time

Common characters typed first are found in the pre-baked static atlas, so nothing is generated for them. Only once characters fall outside that atlas do the two dynamic fallbacks start populating in real time:

  • Dynamic — glyphs are generated from a font bundled in the project (NotoSans_Dynamic SDF).
  • Dynamic OS — glyphs are generated from a font installed on the target machine (CJK_Dynamic SDF), so no large CJK font is shipped with the build.

FAQ

When should I use Static vs Dynamic?
Use Static for characters you know ahead of time: fixed UI labels, ASCII, localized UI text, or any small controlled character set. Use Dynamic for unpredictable text: chat messages, usernames, search fields, player input, or copied text.

Why not use Dynamic for everything?
You can, but it is not always the best tradeoff. A static atlas is predictable, stable, and has no runtime glyph-generation cost. The common case should usually be pre-baked; dynamic fonts are better reserved for characters you cannot predict.

When should I use Dynamic vs Dynamic OS?
Use Dynamic when you want guaranteed coverage from a font file bundled with your project. Use Dynamic OS when you want to use fonts already installed on the player’s device. Dynamic OS is especially useful for large CJK fonts because you avoid adding those font files to your build.

What happens if a dynamic atlas runs out of space?
This demo enables multi-atlas support, so TextMesh Pro allocates another atlas page and keeps adding glyphs. The practical limit is memory. If needed, dynamic font asset data can be cleared at runtime with ClearFontAssetData().


Why this setup matters

Trying to pre-bake every possible Unicode character into one TextMesh Pro atlas is not practical. Fonts with broad CJK coverage alone can be many megabytes, and baking huge glyph sets into SDF atlases would quickly inflate the project size while most glyphs would never be used.

This demo uses a more storage-efficient approach:

  • Common characters are pre-baked into a small Static atlas.
  • European scripts and symbols are handled by a bundled Dynamic fallback font.
  • CJK characters are handled by a Dynamic OS fallback font, so the project does not need to ship a large CJK font file.

The result is a small setup that still supports a very broad range of user-entered text.


Font setup

The demo uses a primary TextMesh Pro font asset with two fallbacks:

Role Asset Mode Purpose Bundled?
Primary UI_Static SDF Static Common ASCII / Latin characters Atlas only
Fallback 1 NotoSans_Dynamic SDF Dynamic Latin Extended, Greek, Cyrillic, symbols Yes
Fallback 2 CJK_Dynamic SDF Dynamic OS Han, Hiragana, Katakana, Hangul No, uses OS font

The fallback order is:

UI_Static SDF
└── NotoSans_Dynamic SDF
    └── CJK_Dynamic SDF

How font lookup works

When TextMesh Pro renders a character, it searches the font chain in order:

  1. It checks the primary static atlas.
  2. If the glyph is missing, it checks the first fallback.
  3. If that fallback can provide the glyph, TextMesh Pro adds it to that fallback’s dynamic atlas.
  4. If not, TextMesh Pro continues to the next fallback.
  5. If no font contains the glyph, the missing-glyph box is shown.

Example:

Hello чащах 漢字
  • Hello is rendered from the static primary atlas.
  • чащах is generated into the bundled dynamic fallback.
  • 漢字 is generated into the Dynamic OS fallback from a system font.

No custom script generates the glyphs. The demo only exposes and monitors TextMesh Pro’s built-in fallback behavior.


How to run

  1. Open the project in Unity 6.

  2. Open Assets/Scenes/SampleScene.unity.

  3. Press Play.

  4. Type or paste mixed-script text into the input field, for example:

    Hello World 123   àáâ ä ç ñ ß   Ω Δ Σ Привет   漢字 こんにちは 안녕하세요   ★ ✓ ➜ € £
    
  5. Watch the HUD in the top-left corner.

The static font count should stay constant, while the dynamic fallback counts grow as new characters are typed. This shows which glyphs were generated at runtime and which atlas handled them.


Scene contents

  • A multiline TMP_InputField using UI_Static SDF as the primary font.
  • A debug HUD showing each font asset’s population mode, character count, glyph count, and atlas size.
  • Console logs that report when a dynamic fallback atlas grows.

Requirements

  • Unity 6
  • URP
  • Input System package
  • A CJK-capable system font for the Dynamic OS fallback, such as Malgun Gothic on Windows

If no suitable OS font is installed, CJK characters will not render. That is expected: the demo intentionally avoids bundling a CJK font file.

About

Unity TextMesh Pro demo: support wide Unicode coverage with static + dynamic fallback fonts, without bundling a huge font.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors