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(assets): TilemapLayer discovery lists BOTH its refs — legacy tilemap scenes rendered nothing

yhh619b1b322e14
diff --git a/sdk/src/component.ts b/sdk/src/component.ts
index bb49eb2d2..d8ba74d2a 100644
--- a/sdk/src/component.ts
+++ b/sdk/src/component.ts
@@ -684,14 +684,23 @@ export const SpineAnimation = defineBuiltin<SpineAnimationData>('SpineAnimation'
export const TilemapLayer = defineBuiltin<TilemapLayerData>('TilemapLayer',
metaDefaults<TilemapLayerData>('TilemapLayer'),
{
- // The `.estileset` reference is carried out-of-band (see tilemapPlugin's scene
- // codec), but it's a real asset dependency: surface it here so the scene asset
- // preloader loads it up front. Then the tilemap sync derives the render table,
- // collision AND animation live from the tileset on the FIRST frame — no lazy-load
- // gap, no baked `collidableTileIds` snapshot needed. This is the single-source model.
+ // A discoverAssets callback is the component's COMPLETE asset manifest
+ // (assetFields are not walked for discovery when one is present), so it
+ // must list both dependencies:
+ // - `tileset`, the legacy copied atlas-texture ref (matches the generated
+ // assetField) — old scenes render from it directly;
+ // - `tilesetAsset`, the out-of-band `.estileset` reference (see
+ // tilemapPlugin's scene codec). Preloading it up front lets the tilemap
+ // sync derive the render table, collision AND animation live from the
+ // tileset on the FIRST frame — no lazy-load gap, no baked
+ // `collidableTileIds` snapshot needed. This is the single-source model.
discoverAssets: (data) => {
+ const refs: AssetRef[] = [];
+ const texture = data.tileset;
+ if (typeof texture === 'string' && texture) refs.push({ type: 'texture', path: texture });
const ref = data.tilesetAsset;
- return typeof ref === 'string' && ref ? [{ type: 'tileset', path: ref }] : [];
+ if (typeof ref === 'string' && ref) refs.push({ type: 'tileset', path: ref });
+ return refs;
},
},
);
diff --git a/sdk/tests/discoverAssets.test.ts b/sdk/tests/discoverAssets.test.ts
index 924f5c4bf..7c8207cc8 100644
--- a/sdk/tests/discoverAssets.test.ts
+++ b/sdk/tests/discoverAssets.test.ts
@@ -6,6 +6,7 @@ import { discoverSceneAssets, getAssetPathsByType } from '../src/asset/discoverA
import { AssetRegistry, makeUuidRef } from '../src/asset/AssetRegistry';
import { StateMachineAgent } from '../src/ai/fsm/StateMachineAgent';
import { BehaviorTreeAgent } from '../src/ai/bt/BehaviorTreeAgent';
+import { TilemapLayer } from '../src/component';
import type { SceneData } from '../src/scene';
const SPRITE_NAME = 'DiscoverTest_Sprite';
@@ -242,6 +243,26 @@ describe('discoverAssets callback authority over assetFields', () => {
});
});
+describe('TilemapLayer discovery covers BOTH its refs (callback = complete manifest)', () => {
+ // Regression: when the discoverAssets callback became authoritative, a
+ // callback returning only tilesetAsset silently dropped the legacy copied
+ // texture ref from discovery — legacy tilemap scenes lost their texture
+ // preload and rendered nothing (0 draw calls).
+ it('legacy copied texture ref AND .estileset ref both bucket', () => {
+ const discover = TilemapLayer.discoverAssets!;
+ expect(discover({ tileset: 'assets/tiles.png', tilesetAsset: 'assets/level.estileset' }))
+ .toEqual([
+ { type: 'texture', path: 'assets/tiles.png' },
+ { type: 'tileset', path: 'assets/level.estileset' },
+ ]);
+ expect(discover({ tileset: 'assets/tiles.png' }))
+ .toEqual([{ type: 'texture', path: 'assets/tiles.png' }]);
+ expect(discover({ tilesetAsset: 'assets/level.estileset' }))
+ .toEqual([{ type: 'tileset', path: 'assets/level.estileset' }]);
+ expect(discover({})).toEqual([]);
+ });
+});
+
describe('FSM/BT agent asset discovery accepts every serialized ref form', () => {
const UUID = 'e43a0ed9-50e9-46d8-b1db-da1c549590a8';