{"record":{"id":"b8acf394c74f81d1","repo":"bevyengine/bevy","slug":"vertex-attribute-attr-must-have-format-expected-before","errorCode":null,"errorMessage":"Vertex attribute {attr:?} must have format {expected:?} before compressing/quantizing","messagePattern":"Vertex attribute (.+?) must have format (.+?) before compressing/quantizing","errorType":"validation","errorClass":"MeshAttributeCompressionError","httpStatus":null,"severity":"error","filePath":"crates/bevy_mesh/src/mesh.rs","lineNumber":3181,"sourceCode":"                        return None;\n                    };\n                    Some((id, data))\n                })\n                .collect()),\n            indices: serialized_mesh.indices.into(),\n            ..Mesh::new(serialized_mesh.primitive_topology, RenderAssetUsages::default())\n        }\n    }\n}\n\n/// Error that can occur when compressing/quantizing mesh vertex attributes.\n#[derive(Error, Debug, Clone)]\npub enum MeshAttributeCompressionError {\n    #[error(\"Vertex attribute {0:?} doesn't exist\")]\n    MissingAttribute(MeshVertexAttributeId),\n    #[error(\"Vertex attribute {0:?} must not be empty\")]\n    EmptyAttribute(MeshVertexAttribute),\n    #[error(\n        \"Vertex attribute {attr:?} must have format {expected:?} before compressing/quantizing\"\n    )]\n    UnsupportedAttributeForCompression {\n        attr: MeshVertexAttribute,\n        expected: VertexFormat,\n    },\n    #[error(\"Vertex attribute {attr:?} must have format `Float32`, `Float32x2` or `Float32x4` before quantizing\")]\n    UnsupportedAttributeForQuantizing { attr: MeshVertexAttribute },\n}\n\n/// Error that can occur when calling [`Mesh::merge_duplicate_vertices`]\n#[derive(Error, Debug, Clone)]\npub enum MeshMergeDuplicateVerticesError {\n    #[error(\"Index attribute already set.\")]\n    IndicesAlreadySet,\n    #[error(\"Mesh access error: {0}\")]\n    MeshAccessError(#[from] MeshAccessError),\n}","sourceCodeStart":3163,"sourceCodeEnd":3199,"githubUrl":"https://github.com/bevyengine/bevy/blob/8d743eb7dc7fcff57a7d5744d0bbf89620b1b145/crates/bevy_mesh/src/mesh.rs#L3163-L3199","documentation":"MeshAttributeCompressionError::UnsupportedAttributeForCompression is thrown when an attribute's current VertexFormat is not one the compression/quantization path can accept as input. The library expects a specific source format (the expected field) before it can compress the attribute's data.","triggerScenarios":"Calling Mesh::compress_attribute (or quantize) on an attribute whose VertexFormat differs from the expected format returned in the error — e.g. the attribute was already compressed, inserted with a non-float format, or its format was changed earlier.","commonSituations":"Running compression twice on the same mesh; authoring meshes with normalized/integer formats (Unorm8, Snorm16, etc.) and then attempting compression; converting an asset pipeline that changes formats upstream.","solutions":["Read the expected VertexFormat from the error and convert the attribute to that format (e.g. via Mesh::transform_attribute_data / reinterpret helpers) before compressing","Only compress uncompressed source formats (typically Float32 variants); skip attributes already in a compressed format","Audit your pipeline for double-compression and guard with a format check before calling compress","Ensure the attribute was inserted with the correct VertexFormat when building the mesh"],"exampleFix":"// before\nmesh.compress_attribute(Mesh::ATTRIBUTE_POSITION.id);\n// after\nif mesh.attribute(Mesh::ATTRIBUTE_POSITION.id).map(|a| a.format()) == Some(VertexFormat::Float32x3) {\n    mesh.compress_attribute(Mesh::ATTRIBUTE_POSITION.id);\n}","handlingStrategy":"validation","validationCode":"fn format_is(mesh: &Mesh, id: MeshVertexAttributeId, expected: VertexFormat) -> bool {\n    mesh.attribute(id).map(|a| a.format()) == Some(expected)\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(MeshAttributeCompressionError::UnsupportedAttributeForCompression { attr, expected }) => {\n        warn!(\"reformat {:?} to {:?} before compressing\", attr, expected);\n    }\n    _ => {}\n}","preventionTips":["Track which pipeline stages change VertexFormat","Guard compression passes with a format check","Never run compression twice on the same mesh"],"tags":["bevy","mesh","vertex-format","compression"],"backgroundTag":"dtype-mismatch","analyzedSha":"8d743eb7dc7fcff57a7d5744d0bbf89620b1b145","analyzedAt":"2026-09-13T03:07:18.343Z","contentChangedAt":"2026-09-13T03:07:18.343Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}