BabylonJS/Babylon.js · error · Error

Event id should be a number

Error message

Event id should be a number

What it means

For an event/send block, the single "event" configuration object must carry the event id as a number in its value array (value[0]). The loader reads eventConfiguration.value?.[0] and throws when it is missing, undefined, or of another type, because the id is used to index parser.arrays.events.

Source

Thrown at packages/dev/loaders/src/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.ts:313

                event: { name: "event" },
            },
            flows: {
                out: { name: "done" },
            },
        },
    },
    "event/send": {
        blocks: [FlowGraphBlockNames.SendCustomEvent],
        extraProcessor(gltfBlock, declaration, _mapping, parser, serializedObjects) {
            // set eventId and eventData. The configuration object of the glTF should have a single object.
            // validate that we are running it on the right block.
            if (declaration.op !== "event/send" || !gltfBlock.configuration || Object.keys(gltfBlock.configuration).length !== 1) {
                throw new Error("Receive event should have a single configuration object, the event itself");
            }
            const eventConfiguration = gltfBlock.configuration["event"];
            const eventId = eventConfiguration.value?.[0];
            if (typeof eventId !== "number") {
                throw new Error("Event id should be a number");
            }
            const event: InteractivityEvent = parser.arrays.events[eventId];
            const serializedObject = serializedObjects[0];
            serializedObject.config ||= {};
            serializedObject.config.eventId = event.eventId;
            serializedObject.config.eventData = event.eventData;
            return serializedObjects;
        },
    },
    "event/receive": {
        blocks: [FlowGraphBlockNames.ReceiveCustomEvent],
        outputs: {
            values: {
                // KHR_interactivity `ref event` output (the event reference).
                event: { name: "event" },
            },
            flows: {
                out: { name: "done" },

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Set configuration.event.value to an array containing the numeric event index, e.g. { "value": [2] }
  2. Check the asset's interactivity events array and use the correct numeric index
  3. Re-export with an up-to-date exporter that writes numeric event ids

Example fix

// before
"configuration": { "event": { "value": ["onHit"] } }
// after
"configuration": { "event": { "value": [2] } }
Defensive patterns

Strategy: type-guard

Validate before calling

function hasNumericEventId(block) {
  return typeof block.configuration?.event?.value?.[0] === "number";
}
// check event/send blocks reference a numeric event index before loading

Type guard

const hasNumericEventId = (b: { configuration?: { event?: { value?: unknown[] } } }): b is { configuration: { event: { value: [number] } } } => typeof b.configuration?.event?.value?.[0] === "number";

Try / catch

try {
  await loader.loadAsync(url);
} catch (e) {
  if (e instanceof Error && e.message === "Event id should be a number") {
    console.error("event/send block value must be a numeric index into the events array.");
  } else throw e;
}

Prevention

When it happens

Trigger: An event/send block whose configuration.event.value array is absent, empty, or contains a non-numeric value (e.g. a string event name instead of the numeric index into the events array).

Common situations: Exporters writing event names instead of indices; hand-edited JSON with a removed value; schema drift between exporter and loader versions.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/791bb8b5eb62952f. Report an issue: GitHub.