Skip to content

3D engine that AI agents drive

Skip malformed recipe fields in the initial asset scan (#2623)

Veeramanikandanr4841eb9e3196b4
diff --git a/changes/2623.md b/changes/2623.md
new file mode 100644
index 00000000..bc5ddab6
--- /dev/null
+++ b/changes/2623.md
@@ -0,0 +1 @@
+- The initial placed-asset scan now skips a malformed `nodes` list, a null node or a non-list `game.npcs`, so the recipe validator names the field instead of a raw `TypeError` (#2623)
diff --git a/docs/game.md b/docs/game.md
index c2e4e8ea..1e5edfea 100644
--- a/docs/game.md
+++ b/docs/game.md
@@ -118,7 +118,7 @@ The `puzzle` sample of `scripts/smoke-game-web.mjs` is two plank crates, two mar
- An NPC needs `rootMotion` and a number parameter `speed`. Its path follower sets `speed`, so idle, walk and run blend; it moves by the root motion, turns at corners and stops at the last of up to 256 `[x, z]` waypoints, where `speed` returns to 0. `cruiseSpeed` is 2.2 by default; `yaw` and `footOffset` work as for the player. Each NPC node is separate from the player and the other NPCs.
- Root travel along +Z works as written; for clips whose root travels -Z set `rootMotion.facing` to `"-z"`.
-A wrong field is refused with its path and the values to use, for example `player.animation.clips.walk.tracks[0].target names "Ghost", which is not a child node of the character`. `window.__game.animation` and `window.__game.npcs` expose the graphs.
+A wrong field is refused with its path and the values to use, for example `player.animation.clips.walk.tracks[0].target names "Ghost", which is not a child node of the character`. `window.__game.animation` and `window.__game.npcs` expose the graphs. A malformed `nodes` or `npcs` table is skipped by the initial asset scan so validation can name the field.
### A placed character
diff --git a/src/agent-scene-assets.js b/src/agent-scene-assets.js
index 30d31ba2..896713dd 100644
--- a/src/agent-scene-assets.js
+++ b/src/agent-scene-assets.js
@@ -169,7 +169,7 @@ export function normalizeAssetPlacement(value) {
export function gamePosedNodeIds(game) {
const ids = new Set();
if (game?.player?.animation && game.player.node) ids.add(game.player.node);
- for (const npc of game?.npcs ?? []) if (npc?.animation && npc.node) ids.add(npc.node);
+ for (const npc of Array.isArray(game?.npcs) ? game.npcs : []) if (npc?.animation && npc.node) ids.add(npc.node);
return ids;
}
@@ -203,7 +203,8 @@ export function recipeAssetNeeds(value) {
collectPlacements(value, placements);
const needs = new Map();
const posedNodes = gamePosedNodeIds(value?.game);
- const posedPlacements = (value?.nodes ?? []).filter(node => node.asset && posedNodes.has(node.id)).map(node => node.asset);
+ const nodes = Array.isArray(value?.nodes) ? value.nodes : [];
+ const posedPlacements = nodes.filter(node => node && typeof node === 'object' && node.asset && posedNodes.has(node.id)).map(node => node.asset);
for (const placement of placements) {
const id = placement.id.toLowerCase();
const need = needs.get(id) ?? { id, copies: 1 };
diff --git a/tests/agent-scene-assets.test.js b/tests/agent-scene-assets.test.js
index 9c2166dd..c7d6cec6 100644
--- a/tests/agent-scene-assets.test.js
+++ b/tests/agent-scene-assets.test.js
@@ -74,6 +74,12 @@ test('material overrides name the source material and stay shared between placem
await assert.rejects(async () => createAgentScene(recipe([{ id: 'bad', asset: { id: ASSET_ID, materials: [{ name: 'Nope', color: [1, 0, 0] }] } }]), {}, { assets: await loadedAssets() }), /^RangeError: nodes\[1\]\.asset\.materials\[0\]\.name: got "Nope"; expected one of "Skin"/);
});
+test('recipeAssetNeeds skips a malformed node list, null node and non-list npcs (#2623)', () => {
+ assert.deepEqual(recipeAssetNeeds({ nodes: {} }), []);
+ assert.deepEqual(recipeAssetNeeds({ nodes: [null] }), []);
+ assert.deepEqual(recipeAssetNeeds({ game: { npcs: {} } }), []);
+});
+
test('a placed clip plays on its own time offset and a seek gives the same frame', async () => {
const nodes = [
{ id: 'walker', translation: [3, 0, 0], asset: { id: ASSET_ID, clip: { index: 0, start: 0.5 } } },