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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
perf(inspector): reuse hierarchy links for selected runtime details
yhh89b64418c706
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 526f8a262..35aa4c75d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Selected runtime details reuse maintained hierarchy links.** Refreshing one entity reads its own parent and children instead of scanning every entity's parent. Child ordering still follows world storage, including after reparenting and draw-order edits; disabled children remain inspectable and native reparenting is read from the current core.+- **Runtime inspectors clear destroyed entity selections.** A selected entity that despawns now returns no detail row instead of an empty ghost entity, including when its native slot is reused. Requests without a live selection or tree avoid traversing the world; disabled live entities remain inspectable.## [0.79.0] - 2026-10-14diff --git a/sdk/src/runtime/worldSnapshot.ts b/sdk/src/runtime/worldSnapshot.tsindex fed204533..b7e1575dd 100644--- a/sdk/src/runtime/worldSnapshot.ts+++ b/sdk/src/runtime/worldSnapshot.ts@@ -95,18 +95,39 @@ export function worldSnapshot(if (!withTree && selectedId == null) return { tree: null, selected: null };const nameDef = getComponent('Name');const parentDef = getComponent('Parent');+ const childrenDef = getComponent('Children');const ownerDef = getComponent('SceneOwner');- const all = world.getAllEntities();+ const all = withTree ? world.getAllEntities() : [];const parentOf = new Map<number, number>();- if (parentDef) {- for (const e of all) {+ const childrenOf = new Map<number, number[]>();+ if (!withTree && selectedId != null && childrenDef) {+ const p = parentDef ? world.tryGet(selectedId as never, parentDef) as { entity?: number } | null : null;+ if (p?.entity !== undefined) parentOf.set(selectedId, p.entity);+ // Native hierarchy writers can move children without updating the SDK's+ // membership cache. Ask the current core before reading this relation.+ const hasChildren = world.resolveHas(childrenDef);+ let c: { entities?: number[] } | null = null;+ if (!hasChildren) {+ c = world.tryGet(selectedId as never, childrenDef) as { entities?: number[] } | null;+ } else if (hasChildren(selectedId as never)) {+ const read = world.resolveGetter(childrenDef, 'retained');+ c = (read ? read(selectedId as never) : world.tryGet(selectedId as never, childrenDef)) as { entities?: number[] } | null;+ }+ if (c?.entities?.length) {+ // Children is maintained with Parent. The inspector's order is the+ // world's storage order, which can differ from attachment order.+ const members = new Set(c.entities);+ childrenOf.set(selectedId, world.getAllEntities().filter(e => members.has(e)));+ }+ } else if (parentDef) {+ const entities = withTree ? all : world.getAllEntities();+ for (const e of entities) {const p = world.tryGet(e, parentDef) as { entity?: number } | null;if (p && p.entity !== undefined) parentOf.set(e as never as number, p.entity);}+ for (const [child, parent] of parentOf) (childrenOf.get(parent) ?? childrenOf.set(parent, []).get(parent)!).push(child);}- const childrenOf = new Map<number, number[]>();- for (const [child, parent] of parentOf) (childrenOf.get(parent) ?? childrenOf.set(parent, []).get(parent)!).push(child);const nameOf = (e: number): string =>(nameDef ? (world.tryGet(e as never, nameDef) as { value?: string } | null)?.value : undefined) ?? `Entity_${e}`;diff --git a/sdk/tests/world-snapshot-visibility-wasm.test.ts b/sdk/tests/world-snapshot-visibility-wasm.test.tsindex e8e941648..66494f83b 100644--- a/sdk/tests/world-snapshot-visibility-wasm.test.ts+++ b/sdk/tests/world-snapshot-visibility-wasm.test.ts@@ -3,7 +3,7 @@ import type { App } from '../src/app/app';import type { ESEngineModule } from '../src/wasm';import { entityIndex } from '../src/types';import { World } from '../src/ecs/world';-import { Sprite, Transform, ensureBuiltinComponentsRegistered } from '../src/ecs/component';+import { Sprite, Transform, Disabled, ensureBuiltinComponentsRegistered } from '../src/ecs/component';import { UINode, UIDisplay } from '../src/ui/core/ui-node';import { worldSnapshot } from '../src/runtime/worldSnapshot';import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';@@ -11,6 +11,38 @@ import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';describe.skipIf(!HAS_WASM)('snapshot visibility with borrowed core values', () => {let module: ESEngineModule;beforeAll(async () => { ensureBuiltinComponentsRegistered(); module = await loadWasmModule(); });+ it('keeps selected hierarchy in tree order after reparenting, reordering and disabled children', () => {+ const registry = new module.Registry(), world = new World();+ world.connectCpp(registry, module);+ const app = { world, hasResource: () => false } as unknown as App;+ try {+ const group = world.spawn('Group'), other = world.spawn('Other');+ const first = world.spawn('First'), second = world.spawn('Second'), third = world.spawn('Third');+ world.setParent(second, group); world.setParent(first, group); world.setParent(third, group);+ world.insert(second, Disabled);+ const verify = (entity: typeof group) => {+ const full = worldSnapshot(app, entity, true);+ expect(worldSnapshot(app, entity, false).selected).toEqual(full.selected);+ const row = full.tree!.entities.find(e => e.id === entity)!;+ expect(full.selected!.parent).toEqual(row.parent);+ expect(full.selected!.children).toEqual(row.children);+ };+ verify(group);+ expect(worldSnapshot(app, group, false).selected!.children).toEqual([first, second, third]);+ world.applyEntityOrder([third, second, first, group, other]);+ verify(group);+ expect(worldSnapshot(app, group, false).selected!.children).toEqual([third, second, first]);+ registry.setParent(second, other); verify(group); verify(other); verify(second);+ world.setParent(first, other); verify(group); verify(other); verify(first);+ world.removeParent(first); world.despawn(third); verify(group); verify(first);+ expect(worldSnapshot(app, group, false).selected!.children).toEqual([]);+ const all = world.getAllEntities;+ world.getAllEntities = () => { throw new Error('leaf detail enumerated the world'); };+ expect(worldSnapshot(app, first, false).selected).toMatchObject({ parent: null, children: [] });+ world.getAllEntities = all;+ } finally { world.disconnectCpp(); registry.delete(); }+ });+it('does not substitute a recycled native entity for a destroyed selection', () => {const registry = new module.Registry(), world = new World();world.connectCpp(registry, module);diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex de68e8cd5..5342eec96 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'perf(inspector): reuse hierarchy links for selected runtime details':+ { note: 'Selected runtime details reuse maintained hierarchy links.' },'fix(inspector): clear destroyed runtime entity selections':{ note: 'Runtime inspectors clear destroyed entity selections.' },'perf(inspector): reuse membership and readers for snapshot visibility':