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.

fix(scene): migrate away retired StateMachine/StateVisuals components

yhhc1484dcc9f54
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index dfd8e84ed..9eb4736a2 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { createStore } from 'zustand/vanilla';
-import { getComponent, getEditorType, Assets, migratePrefabData, extractPrefab, diffAgainstSource, applyOverridesToSource, setTextureParams, TextureFilter, TextureWrap, Renderer } from 'esengine';
+import { getComponent, getEditorType, Assets, migratePrefabData, extractPrefab, diffAgainstSource, applyOverridesToSource, setTextureParams, TextureFilter, TextureWrap, Renderer, RETIRED_COMPONENT_TYPES } from 'esengine';
import { readTextureImportSettings } from './assetImporter';
import type { SceneData, PrefabData, ExtractEntity, ProcessedEntity, PhysicsPluginConfig, AudioProjectConfig, AssetsData } from 'esengine';
import { EngineHost } from '@/engine/EngineHost';
@@ -151,6 +151,27 @@ function unknownComponentTypes(data: SceneData): string[] {
return [...unknown];
}
+/**
+ * Drop components retired by an engine upgrade (see SDK RETIRED_COMPONENT_TYPES)
+ * from a raw scene, in place; returns the retired type names that were present.
+ * These are dead ENGINE types — unlike genuinely-unknown project components (kept
+ * verbatim so they round-trip), they carry no live system. Stripping them out of
+ * the source-of-truth model on open means a save cleans the file, and they never
+ * reach the "unknown project component" warning below. The SDK scene loader drops
+ * them too, so Play never warns "Unknown component type" on them.
+ */
+function stripRetiredComponents(data: SceneData): string[] {
+ const dropped = new Set<string>();
+ for (const entity of data.entities ?? []) {
+ const comps = entity.components;
+ if (!comps) continue;
+ for (let i = comps.length - 1; i >= 0; i--) {
+ if (RETIRED_COMPONENT_TYPES.has(comps[i].type)) { dropped.add(comps[i].type); comps.splice(i, 1); }
+ }
+ }
+ return [...dropped];
+}
+
/** An asset index entry as the registry consumes it (from scanAssets or the
* cached assets.json — same shape). */
type AssetEntryLite = { uuid: string; path: string; type?: string; importer?: Record<string, unknown> };
@@ -353,6 +374,14 @@ class ProjectStoreImpl {
st.workspace.lastOpenedScene ?? st.defaultScene ?? `${st.layout.scenes}/main.esscene`;
const text = await window.estella.fs.read(rel);
const raw = JSON.parse(text) as SceneData;
+ const retired = stripRetiredComponents(raw);
+ if (retired.length > 0) {
+ console.info(
+ `[project] upgraded scene "${rel}": dropped retired engine component(s) ` +
+ `(${retired.join(', ')}). Their behaviour is supplied by successor systems ` +
+ `(e.g. UIController + gears for widgets); save the scene to persist the cleanup.`,
+ );
+ }
const dropped = unknownComponentTypes(raw);
if (dropped.length > 0) {
console.warn(
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index df9512b3e..ac056b715 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1223 stable · 17 beta · 1 deprecated
+Symbols: 1224 stable · 17 beta · 1 deprecated
## ABI_LAYOUT_HASH — const
```
@@ -4788,6 +4788,11 @@ static prototype: QueryInstance<any>
2
```
+## RETIRED_COMPONENT_TYPES — const
+```
+ReadonlySet<string>
+```
+
## RadiusInterestOptions — interface
```
position: ((world: World, entity: Entity) => { x: number; y: number; } | null) | undefined
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 5b0e8e8b9..6ec8038ec 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1222 stable · 19 beta · 1 deprecated
+Symbols: 1223 stable · 19 beta · 1 deprecated
## ANCHOR_AXES — const
```
@@ -4783,6 +4783,11 @@ static prototype: QueryInstance<any>
2
```
+## RETIRED_COMPONENT_TYPES — const
+```
+ReadonlySet<string>
+```
+
## RadiusInterestOptions — interface
```
position: ((world: World, entity: Entity) => { x: number; y: number; } | null) | undefined
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index daf8687c9..d1ee59ef1 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -94,6 +94,7 @@ export {
findEntityByName,
serializeScene,
migrateSceneData,
+ RETIRED_COMPONENT_TYPES,
SCENE_FORMAT_VERSION,
registerSceneComponentCodec,
getComponentAssetFields,
diff --git a/sdk/src/scene.ts b/sdk/src/scene.ts
index f5734d9ec..41ec13737 100644
--- a/sdk/src/scene.ts
+++ b/sdk/src/scene.ts
@@ -300,6 +300,17 @@ const versionNum = (v: string): number => {
return Number.isFinite(n) ? n : 0;
};
+/**
+ * Component types retired by an engine upgrade. A scene authored before the
+ * retirement still serializes them; {@link migrateSceneData} drops them so the
+ * loader never warns "Unknown component type" on dead data, and the editor tells
+ * them apart from genuinely-unknown project components (which it preserves). The
+ * behaviour they encoded lives on in successor systems — the retired UI
+ * StateMachine/StateVisuals pair is superseded by UIController($interaction) +
+ * UIGear, which the widget prefabs now carry.
+ */
+export const RETIRED_COMPONENT_TYPES: ReadonlySet<string> = new Set(['StateMachine', 'StateVisuals']);
+
/**
* Upgrade a SceneData to the current format. Total + idempotent: already-current
* data returns `migrated: false`; migrations are shape-driven so they no-op on
@@ -328,6 +339,10 @@ export function migrateSceneData(raw: SceneData): SceneMigrationResult {
// loader expands them first, so any seen here belong to the sync path
// and are left untouched (spawnAndLoadEntities warns + skips them).
if (isPrefabEntry(entity)) continue;
+ // Drop components retired by an engine upgrade before per-component
+ // normalization — keeping them would only make loadComponent warn + skip.
+ const live = entity.components.filter((c) => !RETIRED_COMPONENT_TYPES.has(c.type));
+ if (live.length !== entity.components.length) { entity.components = live; migrated = true; }
for (const comp of entity.components) {
if (normalizeLegacyComponent(comp)) migrated = true;
}
diff --git a/sdk/tests/scene.test.ts b/sdk/tests/scene.test.ts
index 0af5983e7..0c1a39f8c 100644
--- a/sdk/tests/scene.test.ts
+++ b/sdk/tests/scene.test.ts
@@ -311,6 +311,24 @@ describe('Scene', () => {
.data.entities[0].components[0].data.mode).toBe(1);
});
+ it('drops components retired by an engine upgrade, keeping live ones', () => {
+ const scene: SceneData = {
+ version: '1.0',
+ name: 't',
+ entities: [{
+ id: 0, name: 'Button', parent: null, children: [],
+ components: [
+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 0 } } },
+ { type: 'StateMachine', data: {} },
+ { type: 'StateVisuals', data: { states: [] } },
+ ],
+ }],
+ };
+ const { data, migrated } = migrateSceneData(scene);
+ expect(migrated).toBe(true);
+ expect(data.entities[0].components.map((c) => c.type)).toEqual(['Transform']);
+ });
+
it('reports migrated=true for legacy data, false for current', () => {
expect(migrateSceneData(oneCompScene({ type: 'LocalTransform', data: {} })).migrated).toBe(true);
expect(migrateSceneData(oneCompScene({ type: 'Transform', data: { position: { x: 0, y: 0, z: 0 } } })).migrated).toBe(false);