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(sdk): world.set adds a missing builtin through the full insert path

esengine8b32c7c42a99
diff --git a/sdk/src/world.ts b/sdk/src/world.ts
index 0ed420e38..a0b072f16 100644
--- a/sdk/src/world.ts
+++ b/sdk/src/world.ts
@@ -394,6 +394,14 @@ export class World {
set<C extends AnyComponentDef>(entity: Entity, component: C, data: ComponentData<C>): void {
if (isBuiltinComponent(component)) {
+ // `set` is insert-or-replace: adding a builtin the entity LACKS must run
+ // the full structural bookkeeping (entity set + query dirty + recordAdded),
+ // or the C++ side holds it while queries / has() (entity-set fast path)
+ // never see it. Route the new case through insert.
+ if (this.builtin_.hasCpp && !this.has(entity, component)) {
+ this.insert(entity, component, data as Partial<ComponentData<C>>);
+ return;
+ }
if (this.builtin_.hasCpp) {
try {
const defaults = component._default as Record<string, unknown>;