Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

docs: the Frame Debugger and the UI Debugger get their own pages

yhhd7e580a872d8
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjs
index 7835ca2fb..d26a8f889 100644
--- a/docs/astro/astro.config.mjs
+++ b/docs/astro/astro.config.mjs
@@ -276,6 +276,7 @@ export default defineConfig({
{ label: 'Theming', translations: { 'zh-CN': '主题' }, slug: 'ui/theming' },
{ label: 'Data Binding', translations: { 'zh-CN': '数据绑定' }, slug: 'ui/data-binding' },
{ label: 'Controllers', translations: { 'zh-CN': '控制器' }, slug: 'ui/controllers' },
+ { label: 'UI Debugger', translations: { 'zh-CN': 'UI 调试器' }, slug: 'ui/debugger' },
],
},
{
@@ -325,6 +326,7 @@ export default defineConfig({
{ label: 'Level of Detail', translations: { 'zh-CN': '细节层次(LOD)' }, slug: 'performance/level-of-detail' },
{ label: 'Occlusion Culling', translations: { 'zh-CN': '遮挡剔除' }, slug: 'performance/occlusion-culling' },
{ label: 'Static Batching', translations: { 'zh-CN': '静态合并' }, slug: 'performance/static-batching' },
+ { label: 'Frame Debugger', translations: { 'zh-CN': '帧调试器' }, slug: 'performance/frame-debugger' },
],
},
{
diff --git a/docs/astro/src/content/docs/performance/frame-debugger.mdx b/docs/astro/src/content/docs/performance/frame-debugger.mdx
new file mode 100644
index 000000000..34ddaa624
--- /dev/null
+++ b/docs/astro/src/content/docs/performance/frame-debugger.mdx
@@ -0,0 +1,70 @@
+---
+title: Frame Debugger
+description: Capture one frame in the editor, list its draw calls, see why each one could not batch with the one before it, and replay the frame up to any draw.
+---
+
+The **Frame Debugger** answers "why is this frame so many draw calls?". It captures
+a single frame, lists every draw call in order, and says for each one **why it
+started a new batch** — a different shader, blend mode, material, texture, scissor
+rectangle and so on. It is the editor's view of the same capture the SDK exposes in
+[Profiling & Diagnostics](/docs/performance/profiling/).
+
+Open it with **Window → Frame Debugger**, or search **Frame Debugger** in the Command
+Palette. It docks beside the Profiler.
+
+## Capturing a frame
+
+1. Pick the **realm** to capture: **Viewport** (the editor's own view), **Running
+ game** (during Play), or **Device** (a connected device preview).
+2. Click **Capture frame**. The panel lists the frame as one or more **passes** — a
+ camera pass per camera, plus a screen-overlay pass for UI drawn on top — each with
+ its draw count.
+
+A capture is a snapshot. If the scene changes afterwards the panel says so; capture
+again to look at the new frame.
+
+## Reading the draw list
+
+Every row is one draw call:
+
+| Column | What it shows |
+|---|---|
+| **Type** | What kind of draw it was — sprites, text, a mesh, a tilemap chunk, an effect… |
+| **Break reason** | Why this draw could not join the one before it. |
+| **Drew** | What it drew: material, shader, texture. |
+| **Triangles** | The triangle count. |
+
+The **Break reason** chips above the list filter the rows to one cause. The usual
+ones:
+
+- **First draw of its pass** — nothing to batch with; every pass starts one.
+- **Shader / Material / Blend mode** — the neighbour uses a different one. Sorting
+ entities so that like draws sit together, or sharing a material, removes these.
+- **Texture slots** — the previous draw had used every texture slot. Packing sprites
+ into fewer atlases helps.
+- **Scissor / Stencil** — a UI mask or clip region changed between the two draws.
+- **Depth / Culling / Render state** — a different depth test, face culling or
+ custom state.
+- **Vertex layout / Index gap** — different kinds of geometry that cannot share a
+ buffer run.
+
+## Inspecting one draw
+
+Click a row, or step with **Previous draw** / **Next draw**, to see its details: the
+material, shader, texture, triangles, instances, layer, scissor and stencil, and the
+**entities** it drew (**Select in the Outliner** jumps to one). A draw with no
+entity — a glyph run, a gizmo, an effect — says so.
+
+The viewport can also **replay** the frame up to the selected draw, so you see
+exactly what had been drawn at that point. If a draw cannot be replayed the panel
+tells you rather than showing a wrong picture.
+
+## Using it well
+
+- Capture a **busy** frame, not an idle one, and read the chips first — one cause
+ usually dominates.
+- A pass full of **Blend** and **Material** breaks on a UI canvas means interleaved
+ widgets of different kinds; reorder siblings or merge materials.
+- Pair it with the [Profiler](/docs/performance/profiling/) and
+ [Static Batching](/docs/performance/static-batching/): the Frame Debugger shows
+ *why* draws split, the others show how many and what merging them saved.
diff --git a/docs/astro/src/content/docs/ui/debugger.mdx b/docs/astro/src/content/docs/ui/debugger.mdx
new file mode 100644
index 000000000..b90307742
--- /dev/null
+++ b/docs/astro/src/content/docs/ui/debugger.mdx
@@ -0,0 +1,65 @@
+---
+title: UI Debugger
+description: Inspect a UI tree live — pick an element, record the events it receives, check text for overflow and pseudo-localization, and walk the Tab order.
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The **UI Debugger** is the editor's inspector for the UI tree. Where Details edits an
+entity's components, the Debugger answers *why a control looks or behaves the way it
+does*: what size layout gave it, what input reaches it, whether its text fits, and
+where Tab goes next. Open it from the Command Palette (**UI Debugger**) or the Window
+menu. It reads the **editor world** while you author and the **running world** during
+Play.
+
+It has four views, switched at the top.
+
+## Elements
+
+A searchable **UI hierarchy** on the left and, for the selected node, its real
+component values on the right — including the **computed layout size**, which is what
+layout produced, not what you typed.
+
+- **Pick element** lets you click a UI element in the viewport or Game view instead of
+ hunting through the tree. **Esc** cancels; the picking click is not passed to the game.
+- Values update live. Edit them in Details; edits made during Play revert on Stop.
+
+## Events
+
+Record the events the UI actually dispatches while you play: press **Record events**,
+interact with the game, and read the list — the **target** node, the nodes the event
+**bubbled** through, and whether propagation was **stopped** or the default
+**prevented**. Filter by event type or node.
+
+- It needs a running game: start Play first.
+- It keeps the last 200 records and says when older ones were dropped.
+- Recording does not consume input, and an empty trace alone is not a fault.
+- UI bubbling visits enabled `Interactable` ancestors only; ordinary layout parents are
+ skipped. A `blockRaycast` can end the walk without any stop flag.
+
+## Text
+
+Every `Text` in the scene with its **measured** size next to its **box** and overflow
+mode, so clipped or overflowing labels stand out. Counts for **texts**, **overflow**
+and **to review** sit at the top; **Issues only** hides the rest.
+
+The **Preview** menu re-renders all text as **accent** (letters become accented
+look-alikes — catches fonts missing those glyphs) or **long** (expanded so strings run
+noticeably longer — catches layouts that only fit English). Preview never writes the
+scene's text.
+
+## Focus order
+
+The Tab order of every `Focusable` control, sorted by **Tab index** (ties keep entity
+order), with the reason any control is skipped — disabled, hidden in the tree, or
+outside an open dialog. During Play it also shows the **current focus** and whether it
+is a visible (keyboard) focus. Selecting a row only inspects the entity; it never moves
+focus.
+
+If nothing is listed, add `Focusable` to the controls and capture again.
+
+<Aside>
+The layout readout reports input *candidates*, not hit verdicts: an ancestor mask or an
+occluding sibling can still stop input, so verify clipping and occlusion when a control
+that looks reachable does not respond.
+</Aside>
diff --git a/docs/astro/src/content/docs/zh-cn/performance/frame-debugger.mdx b/docs/astro/src/content/docs/zh-cn/performance/frame-debugger.mdx
new file mode 100644
index 000000000..5e89e440a
--- /dev/null
+++ b/docs/astro/src/content/docs/zh-cn/performance/frame-debugger.mdx
@@ -0,0 +1,54 @@
+---
+title: 帧调试器
+description: 在编辑器里捕获一帧,列出它的每个 draw call,看每一个为什么没能和上一个合批,并把画面重放到任意一个 draw。
+---
+
+**帧调试器**回答"这一帧为什么有这么多 draw call"。它捕获一帧,按顺序列出每个 draw call,
+并给出每个 draw **为什么开了新批**——着色器、混合模式、材质、纹理、裁剪矩形不同等等。
+它是 SDK 在[性能剖析与诊断](/docs/zh-cn/performance/profiling/)里那套帧捕获的编辑器视图。
+
+用 **窗口 → 帧调试器** 打开,或在命令面板里搜**帧调试器**。它停靠在性能分析器旁边。
+
+## 捕获一帧
+
+1. 选**捕获对象**:**视口**(编辑器自己的画面)、**运行中的游戏**(Play 时)、**设备**(已连接的设备预览)。
+2. 点**捕获一帧**。面板把这一帧列成一个或多个 **pass**——每台相机一个相机 pass,
+ 再加一个画在最上面的屏幕叠加层 pass——并显示各自的 draw 数。
+
+捕获是快照。之后场景变了,面板会提示;重新捕获即可看新的一帧。
+
+## 读 draw 列表
+
+每一行是一个 draw call:
+
+| 列 | 含义 |
+|---|---|
+| **类型** | 画的是什么——精灵、文字、网格、瓦片块、特效…… |
+| **断批原因** | 这个 draw 为什么没能并进上一个。 |
+| **内容** | 画了什么:材质、着色器、纹理。 |
+| **三角形** | 三角形数。 |
+
+列表上方的**断批原因**标签可以只看某一种原因。常见的有:
+
+- **所在 pass 的第一个 draw**——没东西可合;每个 pass 都有一个。
+- **着色器 / 材质 / 混合模式**——相邻 draw 用了不同的。把同类 draw 排在一起,或共用材质,可以消除。
+- **纹理槽位**——上一个 draw 已用满纹理槽。把精灵打进更少的图集有帮助。
+- **裁剪 / 模板**——两个 draw 之间 UI 遮罩或裁剪区域变了。
+- **深度 / 剔除 / 渲染状态**——深度测试、背面剔除或自定义状态不同。
+- **顶点布局 / 索引不连续**——几何体种类不同,放不进同一段缓冲。
+
+## 查看单个 draw
+
+点一行,或用**上一个 draw** / **下一个 draw** 逐个走,可以看到它的详情:材质、着色器、纹理、
+三角形、实例数、层、裁剪矩形和模板,以及它画的**实体**(**在大纲中选中**可以跳到该实体)。
+没有实体的 draw——文字、辅助图形、特效——会明说。
+
+视口还能把画面**重放**到所选 draw,让你看到画到那一步时的样子。draw 无法重放时,面板会告诉你,
+而不是给出一张错误的图。
+
+## 用好它
+
+- 捕获**繁忙**的一帧而不是空闲帧,先看标签——通常一种原因占大头。
+- UI 画布的 pass 里一大串**混合模式**和**材质**断批,说明不同种类的控件交错排列;调整兄弟节点顺序或合并材质。
+- 配合[性能分析器](/docs/zh-cn/performance/profiling/)和[静态合并](/docs/zh-cn/performance/static-batching/):
+ 帧调试器告诉你 draw *为什么*拆开,其余的告诉你有多少、合并省了多少。
diff --git a/docs/astro/src/content/docs/zh-cn/ui/debugger.mdx b/docs/astro/src/content/docs/zh-cn/ui/debugger.mdx
new file mode 100644
index 000000000..9f6c0ada2
--- /dev/null
+++ b/docs/astro/src/content/docs/zh-cn/ui/debugger.mdx
@@ -0,0 +1,52 @@
+---
+title: UI 调试器
+description: 实时检查 UI 树——拾取元素、录制它收到的事件、检查文本溢出与伪本地化预览、走一遍 Tab 顺序。
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+**UI 调试器**是编辑器里检查 UI 树的面板。细节面板负责改实体的组件,调试器回答的是
+*一个控件为什么长这样、为什么这样响应*:布局给了它多大、哪些输入能到达它、文字放不放得下、
+Tab 下一步去哪。从命令面板(**UI 调试器**)或窗口菜单打开。编辑时它读**编辑器世界**,
+Play 时读**运行中的世界**。
+
+它有四个视图,在顶部切换。
+
+## 元素
+
+左边是可搜索的 **UI 层级**,右边是所选节点的真实组件值——包括**实际布局尺寸**,
+也就是布局算出来的结果,而不是你填的值。
+
+- **拾取元素**让你直接在视口或游戏视图里点一个 UI 元素,不用在树里翻。**Esc** 取消;拾取的那一下点击不会传给游戏。
+- 数值实时更新。在细节面板里编辑;Play 中的编辑在停止后恢复。
+
+## 事件
+
+录制 UI 在你游玩时实际派发的事件:点**录制事件**,操作游戏,再看列表——**目标节点**、
+事件**冒泡**经过的节点,以及是否**已停止传播**或**已阻止默认行为**。可按事件类型或节点筛选。
+
+- 需要游戏在运行:先开始 Play。
+- 保留最近 200 条记录,有旧记录被丢弃时会提示。
+- 录制不消耗输入;没有记录本身不代表故障。
+- UI 冒泡只经过启用的 `Interactable` 祖先,普通布局父节点会被跳过;`blockRaycast` 可以在没有停止标记的情况下结束这次传播。
+
+## 文本
+
+场景里每个 `Text`,把**测量**尺寸和**容器**尺寸、溢出方式并排放,被裁掉或溢出的标签一眼可见。
+顶部有**文本**、**溢出**、**待复核**的计数,**只看问题**会隐藏其余行。
+
+**预览**菜单把所有文本重新渲染为**重音**(字母换成带变音符号的形近字——能发现缺这些字形的字体)或**加长**
+(字符串明显变长——能发现只适配英文的布局)。预览不会改写场景里的文本。
+
+## 焦点路径
+
+每个 `Focusable` 控件的 Tab 顺序,按 **Tab 索引**排序(同值沿用实体顺序),并说明某个控件为什么被跳过——
+已禁用、层级中已隐藏、或位于打开的弹窗之外。Play 时还会显示**当前焦点**,以及它是否是可见(键盘)焦点。
+选中某一行只是检查该实体,不会移动焦点。
+
+如果什么都没列出,给控件加上 `Focusable` 再重新读取。
+
+<Aside>
+布局读数给出的是输入*候选*,不是命中判定:父级遮罩或遮挡的兄弟节点仍可能挡住输入,
+所以当一个看起来能点到的控件没反应时,要自己核对裁剪和遮挡。
+</Aside>