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
CustomShaderBlockSerializer only knows how to serialize blocks whose getClassName() equals CustomShaderBlock.ClassName. Passing any other BaseBlock is a caller bug, so the serializer throws rather than emitting wrong data.
Source
Thrown at packages/dev/smartFilters/src/blockFoundation/customShaderBlock.serializer.ts:27
/**
* The custom properties of the CustomShaderBlock
*/
customProperties: CustomPropertyData[];
};
type CustomPropertyData = {
name: string;
value: any;
};
/**
* Serializes a CustomShaderBlock to V1 serialized data.
* @param block - The block to serialize
* @returns The serialized block
*/
export const CustomShaderBlockSerializer: SerializeBlockV1 = (block: BaseBlock): ISerializedBlockV1 => {
if (block.getClassName() !== CustomShaderBlock.ClassName) {
throw new Error("Was asked to serialize an unrecognized block type");
}
const customShaderBlock = block as CustomShaderBlock;
let data: CustomShaderBlockData | undefined;
const dynamicPropertyNames = customShaderBlock.dynamicPropertyNames;
if (dynamicPropertyNames.length > 0) {
data = {
customProperties: dynamicPropertyNames.map((propertyName) => ({
name: propertyName,
value: (customShaderBlock as any)[propertyName],
})),
};
}
return {
name: customShaderBlock.name,
uniqueId: customShaderBlock.uniqueId,
blockType: customShaderBlock.blockType,
View on GitHub (pinned to 0592b347b8)
Solutions
- Dispatch to the serializer matching block.getClassName() before calling CustomShaderBlockSerializer.
- Register a dedicated serializer for every custom block class in your serializer map.
- Add a default/fallback serializer path for unknown classes instead of routing them here.
- Log block.getClassName() at the call site to identify the mismatched block.
Example fix
// before
const serialized = CustomShaderBlockSerializer(block);
// after
const serializer = serializers[block.getClassName()];
if (!serializer) throw new Error(`No serializer for ${block.getClassName()}`);
const serialized = serializer(block); Defensive patterns
Strategy: type-guard
Validate before calling
if (block.getClassName() === CustomShaderBlock.ClassName) {
const serialized = CustomShaderBlockSerializer(block);
} Type guard
function isCustomShaderBlock(block: BaseBlock): block is CustomShaderBlock {
return block.getClassName() === CustomShaderBlock.ClassName;
} Try / catch
try {
return CustomShaderBlockSerializer(block);
} catch (e) {
if (e instanceof Error && e.message.includes('unrecognized block type')) {
return serializers[block.getClassName()]?.(block) ?? fallbackSerializer(block);
}
throw e;
} Prevention
- Look up serializers by getClassName() instead of hardcoding one serializer.
- Register a serializer for every custom block class at startup.
- Fail fast with the block class name in your own dispatch error message.
When it happens
Trigger: Registering CustomShaderBlockSerializer as a generic SerializeBlockV1 and invoking it with a block of a different class (e.g. an InputBlock or another custom block).
Common situations: A block-type-to-serializer registry mapping keyed incorrectly, iterating all filter blocks and applying one serializer to each, or a custom block that forgot to define its own serializer.
Related errors
- Was asked to serialize an unrecognized block type
- Could not find a blockType
- blockType must be defined
- `No serializer was provided for a block of type ${block.bloc
- Cannot compare ${a} and ${b}
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/4ccc8def83362515.
Report an issue: GitHub.