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(sdk): a native App runs the same simulation stack as a headless one

esengine070678186bac
diff --git a/sdk/src/ecs/nativeRuntime.ts b/sdk/src/ecs/nativeRuntime.ts
index 576b4fb71..4f6ec83c7 100644
--- a/sdk/src/ecs/nativeRuntime.ts
+++ b/sdk/src/ecs/nativeRuntime.ts
@@ -13,6 +13,9 @@
import { App } from '../app';
import { World } from '../world';
import { inputPlugin } from '../input';
+import { prefabsPlugin } from '../prefabServer';
+import { sceneManagerPlugin } from '../scenePlugin';
+import { headlessBasePlugins } from '../webAppFactory';
import { ensureBuiltinComponentsRegistered } from '../component';
import { installNativePlatform, type NativeBridge } from '../platform/native';
import { createNativeRegistry } from './nativeRegistry';
@@ -69,8 +72,16 @@ export function createNativeApp(
app.connectCpp(createNativeRegistry(scope), undefined, {
memory: new NativeMemoryProvider(scope),
});
- app.addPlugin(inputPlugin);
+ // The same stack a headless app runs — scenes, prefabs, timers, gameplay AI —
+ // plus input. No renderer: the native C++ core owns drawing and reads the ECS
+ // this app authors. assetPlugin is the one exception: it wires the wasm heap,
+ // so installNativeAssets below builds the equivalent over the native RM.
+ // Assets first: prefabs and scene loading declare it as a required resource.
installNativeAssets(app, scope);
+ app.addPlugin(inputPlugin);
+ app.addPlugin(prefabsPlugin);
+ app.addPlugin(sceneManagerPlugin);
+ app.addPlugins(headlessBasePlugins());
return app;
}
diff --git a/sdk/src/webAppFactory.ts b/sdk/src/webAppFactory.ts
index d6a207c14..5791e3491 100644
--- a/sdk/src/webAppFactory.ts
+++ b/sdk/src/webAppFactory.ts
@@ -57,7 +57,9 @@ export interface HeadlessAppOptions {
// (silent on hosts without a device) and replication. Presentation plugins
// (particles, tilemap render, post-process, timeline, UI, spine) stay out —
// they exist to be seen.
-const headlessBasePlugins = (): Plugin[] => [
+/** The simulation stack with no presentation — shared by the headless and
+ * native factories, so neither drifts into its own plugin list. */
+export const headlessBasePlugins = (): Plugin[] => [
timerPlugin, velocityPlugin, lifecyclePlugin, audioPlugin,
perceptionPlugin, fsmPlugin, btPlugin, navPlugin, replicationPlugin,
];