bevyengine/bevy · error · MeshAttributeCompressionError

Vertex attribute must have format before…

Error message

Vertex attribute {attr:?} must have format {expected:?} before compressing/quantizing

What it means

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.

Solutions

  1. 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
  2. Only compress uncompressed source formats (typically Float32 variants); skip attributes already in a compressed format
  3. Audit your pipeline for double-compression and guard with a format check before calling compress
  4. Ensure the attribute was inserted with the correct VertexFormat when building the mesh

Example fix

// before
mesh.compress_attribute(Mesh::ATTRIBUTE_POSITION.id);
// after
if mesh.attribute(Mesh::ATTRIBUTE_POSITION.id).map(|a| a.format()) == Some(VertexFormat::Float32x3) {
    mesh.compress_attribute(Mesh::ATTRIBUTE_POSITION.id);
}
Defensive patterns

Strategy: validation

Validate before calling

fn format_is(mesh: &Mesh, id: MeshVertexAttributeId, expected: VertexFormat) -> bool {
    mesh.attribute(id).map(|a| a.format()) == Some(expected)
}

Try / catch

match result {
    Err(MeshAttributeCompressionError::UnsupportedAttributeForCompression { attr, expected }) => {
        warn!("reformat {:?} to {:?} before compressing", attr, expected);
    }
    _ => {}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of bevyengine/bevy@8d743eb7dc (2026-09-13). Data as JSON: /api/errors/b8acf394c74f81d1. Report an issue: GitHub.

Appendix: source

Thrown at crates/bevy_mesh/src/mesh.rs:3181

                        return None;
                    };
                    Some((id, data))
                })
                .collect()),
            indices: serialized_mesh.indices.into(),
            ..Mesh::new(serialized_mesh.primitive_topology, RenderAssetUsages::default())
        }
    }
}

/// Error that can occur when compressing/quantizing mesh vertex attributes.
#[derive(Error, Debug, Clone)]
pub enum MeshAttributeCompressionError {
    #[error("Vertex attribute {0:?} doesn't exist")]
    MissingAttribute(MeshVertexAttributeId),
    #[error("Vertex attribute {0:?} must not be empty")]
    EmptyAttribute(MeshVertexAttribute),
    #[error(
        "Vertex attribute {attr:?} must have format {expected:?} before compressing/quantizing"
    )]
    UnsupportedAttributeForCompression {
        attr: MeshVertexAttribute,
        expected: VertexFormat,
    },
    #[error("Vertex attribute {attr:?} must have format `Float32`, `Float32x2` or `Float32x4` before quantizing")]
    UnsupportedAttributeForQuantizing { attr: MeshVertexAttribute },
}

/// Error that can occur when calling [`Mesh::merge_duplicate_vertices`]
#[derive(Error, Debug, Clone)]
pub enum MeshMergeDuplicateVerticesError {
    #[error("Index attribute already set.")]
    IndicesAlreadySet,
    #[error("Mesh access error: {0}")]
    MeshAccessError(#[from] MeshAccessError),
}

View on GitHub (pinned to 8d743eb7dc)