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(editor): World gets known-only components; warn only for true unknowns

esengined86e4bc33a11
diff --git a/desktop/src/engine/Reconciler.ts b/desktop/src/engine/Reconciler.ts
index f689dea6b..4e4445c8a 100644
--- a/desktop/src/engine/Reconciler.ts
+++ b/desktop/src/engine/Reconciler.ts
@@ -1,4 +1,4 @@
-import { Name, Parent, resetWorldTo } from 'esengine';
+import { Name, Parent, getComponent, resetWorldTo } from 'esengine';
import type { SceneData } from 'esengine';
import type { EntityId } from '@/types';
import { EngineHost } from './EngineHost';
@@ -24,6 +24,25 @@ const UUID_PREFIX = '@uuid:';
/** Structural/identity components projected explicitly (name, parent), not as data. */
const STRUCTURAL = new Set(['Name', 'Parent', 'Children']);
+/**
+ * The World can only hold components the engine registry knows. Strip the rest
+ * (project/user components like `SpawnMarker`) BEFORE the bulk `resetWorldTo` —
+ * they live in the model (the raw scene) and the incremental path already skips
+ * them. Keeps the World a clean known-only projection AND stops the SDK scene
+ * loader from warning "Unknown component type" on every editor load. Entities are
+ * preserved (only their unknown components are dropped) so the source↔runtime map
+ * stays complete.
+ */
+function worldProjection(data: SceneData): SceneData {
+ return {
+ ...data,
+ entities: (data.entities ?? []).map((e) => ({
+ ...e,
+ components: (e.components ?? []).filter((c) => !!getComponent(c.type)),
+ })),
+ };
+}
+
type AssetResolver = (uuid: string) => number;
const UNRESOLVED: AssetResolver = () => 0;
@@ -63,7 +82,7 @@ export class ReconcilerImpl {
adopt(rawData: SceneData, resolvedData: SceneData): void {
const world = EngineHost.mutableWorld();
if (!world) return;
- const map = resetWorldTo(world, resolvedData as never) as Map<number, EntityId>;
+ const map = resetWorldTo(world, worldProjection(resolvedData) as never) as Map<number, EntityId>;
this.model.adopt(rawData, map);
}
@@ -78,7 +97,7 @@ export class ReconcilerImpl {
const data = this.model.current;
if (!world || !data) return;
const resolved = this.resolveRefs(data) as SceneData;
- const map = resetWorldTo(world, resolved as never) as Map<number, EntityId>;
+ const map = resetWorldTo(world, worldProjection(resolved) as never) as Map<number, EntityId>;
this.model.adopt(data, map);
}
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index 4b7329463..93f70ce21 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -7,7 +7,7 @@ import { Reconciler } from '@/engine/Reconciler';
import { EditorHistory } from '@/engine/EditorHistory';
import { expandScenePrefabs, collapseScenePrefabs } from '@/engine/PrefabInstance';
import { SceneCommands } from '@/engine/SceneCommands';
-import { setUserSchemas, type UserComponentSchema } from '@/engine/schema';
+import { setUserSchemas, userSchema, type UserComponentSchema } from '@/engine/schema';
import { useSelection } from '@/store/selectionStore';
import { Toasts } from '@/store/Toasts';
import { resolveLayout, WORKSPACE_DIR, type OpenedProject, type ProjectLayout, type WorkspaceState } from './format';
@@ -46,12 +46,18 @@ interface ProjectState {
currentScene: string | null;
}
-/** Component types in `data` that the engine doesn't know — dropped on load. */
+/**
+ * Component types in `data` that are genuinely unrecognized — not an engine
+ * builtin AND not a known project component (no `schemas.json` entry). A project
+ * component like `SpawnMarker` IS known (via extracted schema): it's editable +
+ * lossless + runs in Play, so it's not flagged. Only a true typo / missing
+ * declaration is reported.
+ */
function unknownComponentTypes(data: SceneData): string[] {
const unknown = new Set<string>();
for (const entity of data.entities ?? []) {
for (const comp of entity.components ?? []) {
- if (!getComponent(comp.type)) unknown.add(comp.type);
+ if (!getComponent(comp.type) && !userSchema(comp.type)) unknown.add(comp.type);
}
}
return [...unknown];