BabylonJS/Babylon.js · error

Was asked to serialize an unrecognized block type

Error message

Was asked to serialize an unrecognized block type

What it means

InputBlockSerializer is registered for blocks whose blockType equals InputBlockBase.ClassName. Its serialize() first asserts the passed block actually has that blockType, and throws this error when asked to serialize some other block. It is an internal invariant check: block dispatch should have routed the block to a different serializer.

Source

Thrown at packages/dev/smartFilters/src/blockFoundation/inputBlock.serializer.ts:139

 * @param inputBlock - The Vector2 InputBlock to serialize
 * @returns The serialized data for the InputBlock
 */
function SerializeVector2InputBlock(inputBlock: InputBlock<ConnectionPointType.Vector2>): Vector2InputBlockData {
    return {
        inputType: ConnectionPointType.Vector2,
        value: inputBlock.runtimeValue.value,
        appMetadata: inputBlock.appMetadata,
    };
}

/**
 * The V1 serializer for an InputBlock
 */
export const InputBlockSerializer: IBlockSerializerV1 = {
    blockType: InputBlockBase.ClassName,
    serialize: (block: BaseBlock) => {
        if (block.blockType !== InputBlockBase.ClassName) {
            throw new Error("Was asked to serialize an unrecognized block type");
        }
        return {
            name: block.name,
            uniqueId: block.uniqueId,
            blockType: InputBlockBase.ClassName,
            namespace: null,
            comments: block.comments,
            data: SerializeInputBlockData(block as unknown as InputBlockBase),
        };
    },
};

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Verify block.blockType equals InputBlockBase.ClassName before invoking this serializer.
  2. Use SmartFilter.serialize / the block registry dispatch instead of calling InputBlockSerializer.serialize directly.
  3. Register the correct serializer for your custom block type.

Example fix

// before
const data = InputBlockSerializer.serialize(myShaderBlock);
// after
const data = myShaderBlock.blockType === InputBlockBase.ClassName
    ? InputBlockSerializer.serialize(myShaderBlock)
    : BlockSerializerDispatch(myShaderBlock);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(block instanceof InputBlockBase)) {
  throw new TypeError("Expected an InputBlock to serialize");
}

Type guard

function isInputBlock(b: BaseBlock): b is InputBlockBase {
  return b.blockType === InputBlockBase.ClassName;
}

Try / catch

try {
  const data = InputBlockSerializer.serialize(block);
} catch {
  // fall back to the block-type registry dispatch
  const data = SmartFilterSerializer.serializeBlock(block);
}

Prevention

When it happens

Trigger: Passing a non-input BaseBlock (e.g. a ShaderBlock or operator block) directly to InputBlockSerializer.serialize, or registering it as the serializer for another block type in a custom serialization setup.

Common situations: Writing a custom block and mistakenly wiring InputBlockSerializer as its serializer; calling the serializer manually instead of going through SmartFilter.serialize; a block subclass that changed/overrode ClassName.

Related errors


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