Optimize Text Mesh Pro

作者 unity-technologiescb1dccb8f5ad無授權條款1K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Optimizes TextMeshPro rendering, memory, and font setup, including font asset stacks, fallback atlases, SDF quality, and worldspace text. Use when the user asks about TMP fonts, CJK or multilingual text, or text performance.

AI 產生的概覽

指導診斷並修正 Unity TextMeshPro 的字型、圖集、記憶體與算繪問題。

功能
此技能為 Unity TextMeshPro 問題提供分流與修正指引,涵蓋字型資源堆疊、動態備援、內距與取樣比例、SDF 品質、材質預設集,以及世界空間與畫布文字。它會把使用者描述的症狀(例如圖集膨脹、字形模糊、CPU 尖峰、建置大小、中日韓對齊)對應到特定設定與操作步驟。產出的是建議與逐步設定說明,而非程式碼或檔案。
適用情境
當使用者詢問 TextMeshPro 字型、中日韓或多語言文字,或 Unity 中的文字算繪效能時使用。適合用來排查記憶體或圖集膨脹、視覺品質、CPU 成本、建置大小以及在地化對齊問題。
執行需求
此技能不隨附指令碼或資源,僅為指示性內容。它假定使用者熟悉 Unity 編輯器與 TextMeshPro,部分指引涉及 TMP 3.2.0-pre.3 或更新版本。

Optimize TextMeshPro

Triage — identify the symptom first

Before providing tips, identify which category the user's issue falls into. If the user has not described a specific symptom, ask: "Are you seeing a memory/atlas bloat, visual quality, CPU/performance, build size, or localization/alignment issue with TextMeshPro?"

SymptomGo To
Memory Profiler shows large or multiple TMP atlasesFont Stack & Dynamic Fallbacks, Memory Profiler: Include Font Data
Inconsistent glyph weight, fuzzy edges, visual qualityPadding & Sampling Ratios, Font Asset Scale, Atlas Render Mode: SDF16
CPU spikes during text updates or Canvas rebuildsAutoSize, Worldspace vs Canvas Text
Build size too large from shipped font filesDynamic OS Atlas Population
Mixed Latin + CJK alignment looks offFont Normalization
Need multiple font styles (italic, outline, glow)Material Presets

Core Rules

  • Main font = static asset with all glyphs baked in. Add dynamic fallbacks via the Fallback list (or TMP Settings) for everything else. Keep dynamic atlas size at 512-1024 to bound peak memory.
  • Dynamic fallback fonts -> enable Clear Dynamic Data On Build. Otherwise editor-baked glyphs ship in the player.
  • Keep Padding-to-Sampling-Point-Size ratio consistent across primary + fallback fonts. Mismatch produces inconsistent glyph weight on the same line.
  • Latin sampling point size 70-90; CJK 36-50. Different scripts need different sampling sizes for clean SDF.
  • Font asset Scale = 1. Anything else (e.g., 0.9) breaks standard point-size math.
  • Disable AutoSize at runtime once layout is locked. AutoSize is for design, not for live counters.
  • Worldspace text -> use TextMeshPro, not TextMeshProUGUI. Canvas overhead in worldspace is not free.
  • Parent often-changing TMP UI to its own Canvas to bound rebuild cost.
  • TMP material presets > duplicating font assets for italic / bold / outline / glow variants of the same font.
  • For shipping multilingual builds on iOS/Android, evaluate Atlas Population Mode = Dynamic OS (TMP 3.2.0-pre.3+) to leverage system fonts and shrink the build.

Font Stack & Dynamic Fallbacks

If the user reports memory bloat from TMP atlases, advise this font stack pattern:

Main font asset (static, all required Latin glyphs baked)  -> Fallback 1: Dynamic font (atlas 512 or 1024) for CJK  -> Fallback 2: Dynamic font for symbols / emoji

NEVER ship a dynamic fallback font asset without enabling Clear Dynamic Data On Build. Every glyph baked while testing in the editor is included in the player build if this toggle is off.


Padding & Sampling Ratios

If the user reports inconsistent stroke widths or glyph weight differences between primary and fallback fonts, check the padding-to-sampling-point-size ratio.

The ratio is Padding / SamplingPointSize. With Padding = 9 and Sampling Point Size = 90, ratio = 10%.

  • A primary font with one ratio and a fallback with a different ratio produces inconsistent stroke widths on the same line.
  • Pick a ratio (10% is a safe default), apply it to all font assets in the chain.

Recommended sampling point sizes:

  • Latin scripts: 70-90.
  • CJK scripts: 36-50 (CJK glyphs are visually denser; smaller sampling sizes still produce clean SDF and save atlas memory).

Font Asset Scale

If the user reports point sizes not matching design specs, check the font asset Scale value. Some imported TMP font assets ship with Scale = 0.9 instead of 1.0. The Scale value participates in the point-size-to-pixels math, so a non-1 scale produces non-standard point sizes. Advise the user to set Scale = 1 on all font assets before adjusting padding ratios.


Sprite Assets

If the user reports slow loading times for TMP Sprite Assets on mobile, check the source texture's Texture Type. It must be set to Default (not Sprite). Sprite type creates child sub-objects that TMP doesn't use; Default avoids them.


AutoSize

If the user reports CPU spikes on text fields that change frequently (timers, counters, chat, dynamic player names), check whether enableAutoSizing is on. AutoSize resizes the text whenever the string changes, causing constant CPU spikes.

Advise: disable AutoSize and hard-code the chosen point size once layout is locked. Keep AutoSize on only for genuinely static labels that auto-fit on locale change.


Atlas Render Mode: SDF16

If a static font with point size 72 or larger looks unclear or has fuzzy edges, advise switching the Atlas Render Mode to SDF16. Higher precision SDF for big glyphs, at slightly more atlas memory.


Font Normalization

If the user reports misaligned Latin + CJK text on the same line, walk them through this procedure:

  1. Window -> TextMeshPro -> Settings -> Import TMP Example & Extras (one-time per project).
  2. Add the TMP_TextInfoDebugTool component to the TextMeshPro object displaying misaligned text.
  3. Enable ShowLines toggle - the ascender, descender, and baseline render as overlays.
  4. Mix Latin + CJK strings; if the lines diverge, adjust ascender/descender on the TMP Font Asset until they align.

Caveat: importing TMP Examples & Extras has been observed to cause an infinite import loop on some project layouts. If it happens, close Unity and re-open - the import resolves on the second attempt.


Material Presets

If the user needs multiple styles (italic, bold, outline, glow) of the same font, advise material presets instead of duplicating font assets. Presets share the same font texture but override shader parameters.

How to create:

  1. Select a TMP Text GameObject.
  2. In Inspector, find the Material section.
  3. Right-click the Material header -> Create Material Preset.
  4. Rename the new material and tweak settings.
  5. On the TMP Text component, pick the preset from the Material Preset dropdown.

Dynamic OS Atlas Population (TMP 3.2.0-pre.3)

If the user is shipping multilingual builds and concerned about build size, advise evaluating Atlas Population Mode = Dynamic OS (TMP 3.2.0-pre.3+):

  • In Editor: still uses the source font from the project.
  • In a player build: the source font is not included. At runtime, Unity searches the device for a font with the matching Family + Style name.

Recommended system fonts for CJK:

PlatformRecommended system font
AndroidNotoSans (covers Chinese, Japanese, Korean glyphs broadly).
iOSPingFang for Simplified/Traditional Chinese. iOS uses unique fonts per language for CJK (different families for Chinese, Japanese, Korean) - check the fallback chain when shipping a single TMP setup across all three.

Wins: build size shrinks (no shipped CJK font files) and memory drops (system font is shared with the OS).


Memory Profiler: Include Font Data

If Memory Profiler shows unexpectedly large font asset sizes in the Editor, check whether Include Font Data is enabled on the .ttf / .ttc import settings. The Editor includes the source font file in the asset by default, but on device (especially with Dynamic OS), this cost is not paid.

To make Editor captures match device: on the font file -> deselect Include Font Data in the import settings. Memory Profiler will then show overhead without the underlying font file.


Worldspace vs Canvas Text

If the user has worldspace text (damage numbers, signs, holograms) using TextMeshProUGUI, advise switching to TextMeshPro. Worldspace Canvas is a known inefficiency.

If a TextMeshProUGUI element's text changes often (timers, counters, chat), advise parenting it under a child GameObject with its own Canvas component. Canvas rebuilds are scoped per-Canvas, so isolating the volatile field cuts rebuild cost on the rest of the UI.


Common Pitfalls

If the user's setup matches any of these, flag it:

  • One giant dynamic font asset for all languages instead of static main + dynamic fallback - the dynamic atlas balloons.
  • Inconsistent padding ratio across primary + fallback - same line of text looks like two fonts.
  • Font asset Scale = 0.9 inherited from import - point sizes won't match design specs.
  • Leaving AutoSize on for live counters - hidden CPU spikes.
  • World-space TextMeshProUGUI inside a worldspace Canvas - extra rebuilds for no benefit; use TextMeshPro.
  • Forgetting Clear Dynamic Data On Build on dynamic fallback fonts - editor-test glyphs ship in the player.
  • Capturing Memory Profiler in Editor with Include Font Data on, then being surprised the on-device build is smaller.
  • Sprite asset source texture set to Sprite type - mobile loading slows from extra child sub-objects.

References

來源與署名

來源:unity-technologies/skills位於skills/optimize-text-mesh-pro提交cb1dccb

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架