{"record":{"id":"374b6c4120771838","repo":"bevyengine/bevy","slug":"the-requested-mesh-data-wasn-t-found-in-this-mesh","errorCode":null,"errorMessage":"The requested mesh data wasn't found in this mesh","messagePattern":"The requested mesh data wasn't found in this mesh","errorType":"exception","errorClass":"MeshAccessError","httpStatus":null,"severity":"error","filePath":"crates/bevy_mesh/src/mesh.rs","lineNumber":42,"sourceCode":"use bevy_reflect::{std_traits::ReflectDefault, Reflect};\nuse bytemuck::cast_slice;\nuse core::hash::{Hash, Hasher};\nuse core::ptr;\n#[cfg(feature = \"serialize\")]\nuse serde::{Deserialize, Serialize};\nuse thiserror::Error;\nuse tracing::warn;\nuse wgpu_types::{VertexAttribute, VertexFormat, VertexStepMode, WriteOnly};\n\npub const INDEX_BUFFER_ASSET_INDEX: u64 = 0;\npub const VERTEX_ATTRIBUTE_BUFFER_ID: u64 = 10;\n\n/// Error from accessing mesh vertex attributes or indices\n#[derive(Error, Debug, Clone)]\npub enum MeshAccessError {\n    #[error(\"The mesh vertex/index data has been extracted to the RenderWorld (via `Mesh::asset_usage`)\")]\n    ExtractedToRenderWorld,\n    #[error(\"The requested mesh data wasn't found in this mesh\")]\n    NotFound,\n}\n\nconst MESH_EXTRACTED_ERROR: &str = \"Mesh has been extracted to RenderWorld. To access vertex attributes, the mesh `asset_usage` must include `MAIN_WORLD`\";\n\n// storage for extractable data with access methods which return errors if the\n// contents have already been extracted\n#[derive(Debug, Clone, PartialEq, Reflect, Default)]\nenum MeshExtractableData<T> {\n    Data(T),\n    #[default]\n    NoData,\n    ExtractedToRenderWorld,\n}\n\nimpl<T> MeshExtractableData<T> {\n    // get a reference to internal data. returns error if data has been extracted, or if no\n    // data exists","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_mesh/src/mesh.rs#L24-L60","documentation":"MeshAccessError::NotFound comes from the MeshExtractableData accessors when the requested slot holds NoData (crates/bevy_mesh/src/mesh.rs:64), or from attribute-id lookups that miss (mesh.rs:535, 613, 664). It means the requested vertex attribute or index data simply does not exist in this mesh: it was never inserted, or the attribute id is absent from the mesh's map.","triggerScenarios":"Accessing a required attribute that was never inserted (e.g. normals on a primitive built without them) via the try_attribute/as_mut APIs; calling mutating accessors on a mesh that holds no attributes or indices at all (NoData state).","commonSituations":"Assuming every mesh has normals/tangents/Uvs; procedurally generated meshes that skip optional attributes; code that queries an attribute id by a different name/id than the one inserted.","solutions":["Insert the attribute before accessing it (e.g. mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, ...))","Check presence first with the Option-returning API: mesh.attribute(Mesh::ATTRIBUTE_NORMAL).is_some()","Handle Err(MeshAccessError::NotFound) by supplying a sensible default or skipping the mesh"],"exampleFix":"// before\nlet normals = mesh.try_attribute_mut(Mesh::ATTRIBUTE_NORMAL)?; // Err(NotFound)\n\n// after\nif mesh.attribute(Mesh::ATTRIBUTE_NORMAL).is_none() {\n    mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, vec![[0.0, 1.0, 0.0]; mesh.count_vertices()]);\n}\nlet normals = mesh.try_attribute_mut(Mesh::ATTRIBUTE_NORMAL)?;","handlingStrategy":"try-catch","validationCode":"let has_normals = mesh.attribute(Mesh::ATTRIBUTE_NORMAL).is_some();\nif !has_normals {\n    mesh.insert_attribute(\n        Mesh::ATTRIBUTE_NORMAL,\n        vec![[0.0, 1.0, 0.0]; mesh.count_vertices()],\n    );\n}","typeGuard":"fn has_attribute(mesh: &Mesh, id: MeshVertexAttributeId) -> bool {\n    mesh.attribute_id(id).is_some()\n}","tryCatchPattern":"match mesh.try_attribute(Mesh::ATTRIBUTE_NORMAL) {\n    Ok(values) => { /* use values */ }\n    Err(MeshAccessError::NotFound) => { /* attribute absent: insert it or skip */ }\n    Err(MeshAccessError::ExtractedToRenderWorld) => { /* fix asset_usage or use a CPU copy */ }\n}","preventionTips":["Check attribute presence with the Option API before using the Result API","Generate defaults for optional attributes (normals, tangents, UVs) right after mesh creation","Log which attributes a mesh actually contains before processing it"],"tags":["bevy","bevy-mesh","rust","mesh","vertex-attributes","missing-data"],"backgroundTag":"missing-mesh-attribute","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}