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.

feat(details): prefab instance Revert + Select Asset in the prefab bar

esengine4d14ac53eb14
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index 7432e60c7..e4ea5817a 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -1775,6 +1775,25 @@ function EditorDetails() {
<Package size={13} strokeWidth={1.8} />
</span>
<span className="pn">{prefabName}</span>
+ <span className="pacts">
+ <button
+ type="button"
+ title="Select the prefab asset in the Content Browser"
+ onClick={() => {
+ const info = prefabRef ? ProjectStore.assetInfo(prefabRef) : null;
+ if (info) useSelection.getState().selectAsset(info.path);
+ }}
+ >
+ <FolderOpen size={12} strokeWidth={1.9} /> Select
+ </button>
+ <button
+ type="button"
+ title="Revert all overrides — re-sync this instance to the prefab"
+ onClick={() => void ProjectStore.revertPrefabInstance(selectedId)}
+ >
+ <RotateCcw size={12} strokeWidth={1.9} /> Revert
+ </button>
+ </span>
</div>
)}
</div>
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index 701838ae9..2f5c17ee7 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -445,6 +445,31 @@ class ProjectStoreImpl {
return rootId;
}
+ /**
+ * Revert a prefab instance to the prefab (Details "Revert"): re-sync the whole
+ * instance to the asset, discarding all overrides, keeping its placement. Works on
+ * any entity of the instance (resolves to the instance root). Implemented by
+ * composing the existing, tested delete + re-instantiate commands — so it can't
+ * desync; the cost is two undo steps (delete, then instantiate). Returns the fresh
+ * root's source id, or null if the entity isn't a prefab instance.
+ */
+ async revertPrefabInstance(sourceId: number): Promise<number | null> {
+ const tag = SceneModel.prefabTag(sourceId);
+ const instanceRoot = tag?.instanceRoot ?? sourceId;
+ const ref = SceneModel.prefabTag(instanceRoot)?.prefab;
+ if (!ref) return null;
+ const info = this.assetInfo(ref);
+ if (!info) return null;
+ const root = SceneModel.entityBySource(instanceRoot);
+ const parent = root?.parent ?? null;
+ const tf = root?.components.find((c) => c.type === 'Transform')?.data as
+ | { position?: { x: number; y: number } }
+ | undefined;
+ const position = tf?.position ? { x: tf.position.x, y: tf.position.y } : undefined;
+ SceneCommands.deleteEntity(instanceRoot);
+ return this.instantiatePrefabFromPath(info.path, parent, position);
+ }
+
/**
* Spawn a Sprite entity from an image asset dropped into the viewport: resolve its
* texture ref (preloading it so it renders), read the image's natural pixel size,
diff --git a/desktop/src/theme/inspector.css b/desktop/src/theme/inspector.css
index 075fdc19b..3951a1576 100644
--- a/desktop/src/theme/inspector.css
+++ b/desktop/src/theme/inspector.css
@@ -60,7 +60,8 @@
.prefab-bar { display: flex; align-items: center; gap: 7px; margin-top: 7px; padding: 5px 8px; background: var(--acc-soft); border: 1px solid rgba(47,136,214,0.25); border-radius: var(--r-sm); font-size: var(--fs-xs); }
.prefab-bar .pic { color: var(--acc-hi); flex-shrink: 0; display: grid; place-items: center; }
.prefab-bar .pn { color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-.prefab-bar button { font-size: var(--fs-2xs); color: var(--acc-hi); padding: 2px 5px; border-radius: var(--r-xs); transition: background var(--t-fast); }
+.prefab-bar .pacts { display: flex; gap: 4px; flex-shrink: 0; }
+.prefab-bar button { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-2xs); color: var(--acc-hi); padding: 2px 6px; border-radius: var(--r-xs); transition: background var(--t-fast); }
.prefab-bar button:hover { background: var(--acc-soft-2); }
/* component / category */