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
fix(inspector): read current native parent membership in runtime snapshots
yhh0f7d4fd9c0cf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f73d524b4..d10ad69a1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Runtime hierarchy inspection follows native parent additions and removals.** The tree and selected details use current component membership before reading a parent, so native edits appear immediately even when the SDK's cached hierarchy membership is stale. Detaching a node clears its parent instead of reporting the empty getter's sentinel; disabled nodes remain included.+- **Runtime tree inspection indexes script component names once per snapshot.** Large script catalogues no longer require a name search for every component on every entity. The index is rebuilt for each group read, so registration, removal, aliases and context changes remain visible; builtin membership is still read from the current core.- **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.diff --git a/sdk/src/runtime/worldSnapshot.ts b/sdk/src/runtime/worldSnapshot.tsindex 2b2f36c20..b91b7bbee 100644--- a/sdk/src/runtime/worldSnapshot.ts+++ b/sdk/src/runtime/worldSnapshot.ts@@ -98,12 +98,23 @@ export function worldSnapshot(const childrenDef = getComponent('Children');const ownerDef = getComponent('SceneOwner');const all = withTree ? world.getAllEntities() : [];+ const treeTypes = withTree ? world.getComponentTypesBatch(all) : null;+ const detailTypes = !withTree && selectedId != null ? world.getComponentTypes(selectedId as never) : null;+ let parentReader: ReturnType<World['resolveGetter']> | undefined;+ const parentValue = (entity: number, types: string[]): number | undefined => {+ if (!parentDef || !types.includes(parentDef._name)) return undefined;+ if (parentReader === undefined) parentReader = world.resolveGetter(parentDef);+ // Membership comes from the current core, not the SDK's hierarchy cache.+ // Only the scalar escapes a reader that may borrow its component value.+ const p = (parentReader ? parentReader(entity as never) : world.get(entity as never, parentDef)) as { entity?: number } | null;+ return p?.entity;+ };const parentOf = new Map<number, number>();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);+ const parent = parentValue(selectedId, detailTypes!);+ if (parent !== undefined) parentOf.set(selectedId, parent);// 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);@@ -122,9 +133,10 @@ export function worldSnapshot(}} 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);+ const types = treeTypes ?? world.getComponentTypesBatch(entities);+ for (let i = 0; i < entities.length; i++) {+ const parent = parentValue(entities[i], types[i]);+ if (parent !== undefined) parentOf.set(entities[i], parent);}for (const [child, parent] of parentOf) (childrenOf.get(parent) ?? childrenOf.set(parent, []).get(parent)!).push(child);}@@ -165,7 +177,6 @@ export function worldSnapshot(};let selectedTypes: string[] | null = null;- const treeTypes = withTree ? world.getComponentTypesBatch(all) : null;const tree = withTree? {version: '1.0' as const, name: 'live' as const,@@ -180,7 +191,7 @@ export function worldSnapshot(let selected: SnapshotEntity | null = null;if (selectedId != null) {- const types = selectedTypes ?? world.getComponentTypes(selectedId as never);+ const types = selectedTypes ?? detailTypes ?? world.getComponentTypes(selectedId as never);const raw = filterInspectableTypes(types).map((type) => {const def = getComponent(type);diff --git a/sdk/tests/world-snapshot-visibility-wasm.test.ts b/sdk/tests/world-snapshot-visibility-wasm.test.tsindex 66494f83b..e1827522f 100644--- a/sdk/tests/world-snapshot-visibility-wasm.test.ts+++ b/sdk/tests/world-snapshot-visibility-wasm.test.ts@@ -11,6 +11,37 @@ 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.each([[true, true], [false, true], [true, false]])('reflects native parent edits with bulk inspection %s and reader %s', (bulk, reader) => {+ const registry = new module.Registry(), world = new World();+ if (!bulk) registry.getBuiltinComponentNames = undefined;+ world.connectCpp(registry, module);+ if (!reader) {+ const read = world.resolveGetter.bind(world);+ world.resolveGetter = (component, mode) => component._name === 'Parent' ? null : read(component, mode);+ }+ const app = { world, hasResource: () => false } as unknown as App;+ try {+ const warm = world.spawn('Warm group'), group = world.spawn('Native group'), child = world.spawn('Child');+ world.setParent(child, warm); world.removeParent(child);+ world.insert(child, Disabled);+ registry.setParent(child, group);+ const before = worldSnapshot(app, child, true);+ expect(before.selected!.parent).toBe(group);+ expect(before.tree!.entities.find(e => e.id === child)!.parent).toBe(group);+ expect(before.tree!.entities.find(e => e.id === group)!.children).toEqual([child]);+ expect(worldSnapshot(app, child, false).selected!.parent).toBe(group);+ expect(worldSnapshot(app, group, false).selected!.children).toEqual([child]);+ world.setParent(child, warm);+ registry.removeParent(child);+ const after = worldSnapshot(app, child, true);+ expect(after.selected!.parent).toBeNull();+ expect(after.tree!.entities.find(e => e.id === child)!.parent).toBeNull();+ expect(after.tree!.entities.find(e => e.id === warm)!.children).toEqual([]);+ expect(worldSnapshot(app, child, false).selected!.parent).toBeNull();+ expect(before.selected!.parent).toBe(group);+ } finally { world.disconnectCpp(); registry.delete(); }+ });+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);diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 43f05a470..2e0ae9c49 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 = {+ 'fix(inspector): read current native parent membership in runtime snapshots':+ { note: 'Runtime hierarchy inspection follows native parent additions and removals.' },'perf(inspector): index script names once per runtime tree snapshot':{ note: 'Runtime tree inspection indexes script component names once per snapshot.' },'perf(inspector): reuse hierarchy links for selected runtime details':