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: restore scene state after stopping shared play mode

esengine3e6fa437aae1
diff --git a/editor/src/Editor.ts b/editor/src/Editor.ts
index 6460a5098..fc6b00452 100644
--- a/editor/src/Editor.ts
+++ b/editor/src/Editor.ts
@@ -112,7 +112,7 @@ export class Editor {
constructor(container: HTMLElement, options?: EditorOptions) {
this.container_ = container;
- this.store_ = new EditorStore();
+ this.store_ = getEditorStore();
this.projectPath_ = options?.projectPath ?? null;
this.panelManager_ = new PanelManager();
diff --git a/editor/src/panels/game-view/GameViewPanel.ts b/editor/src/panels/game-view/GameViewPanel.ts
index 6fbef776a..2074d8276 100644
--- a/editor/src/panels/game-view/GameViewPanel.ts
+++ b/editor/src/panels/game-view/GameViewPanel.ts
@@ -157,7 +157,7 @@ export class GameViewPanel implements PanelInstance, Resizable {
if (this.gameRenderer_) {
this.gameRenderer_.setVisible(false);
}
- getPlayModeService().exitShared();
+ await getPlayModeService().exitShared();
await this.gameManager_.stop();
}
diff --git a/editor/src/renderer/SharedRenderContext.ts b/editor/src/renderer/SharedRenderContext.ts
index a17d78958..5ea176d7a 100644
--- a/editor/src/renderer/SharedRenderContext.ts
+++ b/editor/src/renderer/SharedRenderContext.ts
@@ -295,14 +295,19 @@ export class SharedRenderContext {
this.requestRender();
}
- exitPlayMode(): void {
+ async exitPlayMode(scene?: import('../types/SceneTypes').SceneData): Promise<void> {
this.playMode_ = false;
this.paused_ = false;
setPlayMode(false);
this.clearInputState();
- const cam = this.getUICameraInfo();
- if (cam) cam.valid = false;
- this.stopContinuousRender();
+
+ if (scene && this.sceneManager_) {
+ await this.sceneManager_.loadScene(scene);
+ if (this.app_) {
+ this.app_.tick(0);
+ }
+ this.requestRender();
+ }
}
pausePlay(): void {
diff --git a/editor/src/services/PlayModeService.ts b/editor/src/services/PlayModeService.ts
index 69f55e9d7..22dc6d58d 100644
--- a/editor/src/services/PlayModeService.ts
+++ b/editor/src/services/PlayModeService.ts
@@ -58,19 +58,20 @@ class PlayModeService {
this.emitStateChange();
}
- exitShared(): void {
+ async exitShared(): Promise<void> {
if (!this.sharedMode_) return;
- getSharedRenderContext().exitPlayMode();
-
+ const snapshot = this.snapshot_;
+ this.snapshot_ = null;
this.sharedMode_ = false;
this.state_ = 'stopped';
this.cachedEntities_ = [];
this.selectedEntityId_ = null;
- if (this.snapshot_) {
- getEditorStore().restoreSnapshot(this.snapshot_);
- this.snapshot_ = null;
+ await getSharedRenderContext().exitPlayMode(snapshot?.scene);
+
+ if (snapshot) {
+ getEditorStore().restoreSnapshot(snapshot);
}
this.emitStateChange();