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): resolve play-realm audio paths against the project root

yhh2bb9defaa3a3
diff --git a/desktop/src/playHost.ts b/desktop/src/playHost.ts
index 99354a3f4..ad5c0b98f 100644
--- a/desktop/src/playHost.ts
+++ b/desktop/src/playHost.ts
@@ -82,6 +82,7 @@ type InitMessage = Extract<PlayOutbound, { type: 'estella:play:init' }>;
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
const wasmBase = new URL('./wasm/', import.meta.url).href; // sibling of host.js
const bundleUrl = new URL('../cache/scripts.mjs', import.meta.url).href; // project bundle
+const projectBase = new URL('../../', import.meta.url).href.replace(/\/$/, ''); // project root — assets live here
function resize(): void {
const dpr = window.devicePixelRatio || 1;
@@ -179,6 +180,8 @@ async function buildAppAndRun(msg: InitMessage): Promise<void> {
canvas,
sceneData: msg.sceneData,
assetManifest: msg.assetManifest,
+ // playSFX/playBGM take project-relative paths — resolve them against the project root.
+ assetBaseUrl: projectBase,
// physics.wasm is served next to esengine.wasm; load it on demand.
wasmBaseUrl: wasmBase.replace(/\/$/, ''),
physicsEnabled: msg.physicsEnabled,
diff --git a/sdk/src/playRealmRuntime.ts b/sdk/src/playRealmRuntime.ts
index 4d4317cb9..018e2d56d 100644
--- a/sdk/src/playRealmRuntime.ts
+++ b/sdk/src/playRealmRuntime.ts
@@ -17,6 +17,7 @@
*/
import type { App } from './app';
import type { ESEngineModule } from './wasm';
+import { Audio } from './audio/Audio';
import { initRuntime } from './runtimeLoader';
import type { RuntimeAssetSource } from './runtimeAssets';
import { HttpBackend } from './asset/Backend';
@@ -39,6 +40,11 @@ export interface PlayRealmRuntimeConfig {
/** Base URL the engine side-modules (physics.wasm, …) are served from — same
* dir as esengine.wasm. When set, the realm can load physics on demand. */
wasmBaseUrl?: string;
+ /** Project-root URL for path-addressed runtime assets. Textures resolve
+ * through the uuid manifest, but the audio channel takes plain project-relative
+ * paths (`audio.playSFX('assets/…')`), so it needs this base to fetch from the
+ * project rather than the play-realm subdir. */
+ assetBaseUrl?: string;
/** Project-declared physics enable (`.uproject` features analog) — installs
* physics even for runtime-spawned bodies the static scene doesn't show. */
physicsEnabled?: boolean;
@@ -79,8 +85,14 @@ function createPlayRealmSource(manifest: Record<string, string>): RuntimeAssetSo
* register the snapshot as the sole scene, wire a fetch-backed source, and run.
*/
export async function initPlayRealmRuntime(config: PlayRealmRuntimeConfig): Promise<void> {
- const { app, module, canvas, sceneData, assetManifest } = config;
+ const { app, module, canvas, sceneData, assetManifest, assetBaseUrl } = config;
const source = createPlayRealmSource(assetManifest);
+ // Point the audio channel at the project root: playSFX/playBGM take project-
+ // relative paths, not uuid refs, so without this they resolve against the
+ // play-realm subdir and 404.
+ if (assetBaseUrl && app.hasResource(Audio)) {
+ app.getResource(Audio).baseUrl = assetBaseUrl;
+ }
await initRuntime({
app,
module,