{"record":{"id":"967a6a83a75bde3e","repo":"bevyengine/bevy","slug":"the-given-entity-entity-does-not-have-a-comp","errorCode":null,"errorMessage":"The given `Entity` {entity} does not have a `{component_name:?}` component ({component_id:?}, which corresponds to {type_id:?})","messagePattern":"The given `Entity` (.+?) does not have a `(.+?)` component \\((.+?), which corresponds to (.+?)\\)","errorType":"exception","errorClass":"GetComponentReflectError::EntityDoesNotHaveComponent","httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/world/reflect.rs","lineNumber":225,"sourceCode":"    }\n}\n\n/// The error type returned by [`World::get_reflect`] and [`World::get_reflect_mut`].\n#[derive(Error, Debug)]\npub enum GetComponentReflectError {\n    /// There is no [`ComponentId`] corresponding to the given [`TypeId`].\n    ///\n    /// This is usually handled by calling [`App::register_type`] for the type corresponding to\n    /// the given [`TypeId`].\n    ///\n    /// See the documentation for [`bevy_reflect`] for more information.\n    ///\n    /// [`App::register_type`]: ../../../bevy_app/struct.App.html#method.register_type\n    #[error(\"No `ComponentId` corresponding to {0:?} found (did you call App::register_type()?)\")]\n    NoCorrespondingComponentId(TypeId),\n\n    /// The given [`Entity`] does not have a [`Component`] corresponding to the given [`TypeId`].\n    #[error(\"The given `Entity` {entity} does not have a `{component_name:?}` component ({component_id:?}, which corresponds to {type_id:?})\")]\n    EntityDoesNotHaveComponent {\n        /// The given [`Entity`].\n        entity: Entity,\n        /// The given [`TypeId`].\n        type_id: TypeId,\n        /// The [`ComponentId`] corresponding to the given [`TypeId`].\n        component_id: ComponentId,\n        /// The name corresponding to the [`Component`] with the given [`TypeId`], or `None`\n        /// if not available.\n        component_name: Option<DebugName>,\n    },\n\n    /// The [`World`] was missing the [`AppTypeRegistry`] resource.\n    #[error(\"The `World` was missing the `AppTypeRegistry` resource\")]\n    MissingAppTypeRegistry,\n\n    /// The [`World`]'s [`TypeRegistry`] did not contain [`TypeData`] for [`ReflectFromPtr`] for the given [`TypeId`].\n    ///","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/world/reflect.rs#L207-L243","documentation":"GetComponentReflectError::EntityDoesNotHaveComponent is returned by World::get_reflect / get_reflect_mut when the TypeId resolves to a valid registered component, but the specific Entity you asked about simply does not carry that component. The error embeds the entity, type id, component id and (when known) the component name so you can tell exactly what was missing on which entity.","triggerScenarios":"world.get_reflect(entity, TypeId::of::<T>()) where entity lacks T — e.g. iterating a query of entities and reflecting a component only some of them have, reflecting an entity after its component was removed this frame, or assuming a required/child entity has the component.","commonSituations":"Editor/inspector code that reflects arbitrary selected entities; scene serialization walking all entities for optional components; race where a removal command or observer stripped the component between selection and reflection.","solutions":["Pre-check with the typed API: world.get::<T>(entity).is_some(), or world.get_by_id(entity, component_id).is_some() when you only have ids.","Match on the error variant and treat it as the normal 'entity lacks this component' path instead of bubbling it up.","Narrow the entity set with a Query<(Entity, &T)> so every reflected entity is guaranteed to have the component.","If removal is expected mid-frame, defer reflection to a schedule that runs after command flush."],"exampleFix":"// before\nlet field = world.get_reflect_mut(entity, TypeId::of::<Health>())?; // EntityDoesNotHaveComponent\n\n// after\nmatch world.get_reflect_mut(entity, TypeId::of::<Health>()) {\n    Ok(Some(mut field)) => { /* mutate */ }\n    Ok(None) => { /* entity exists but lacks Health */ }\n    Err(GetComponentReflectError::EntityDoesNotHaveComponent { entity, .. }) => {\n        debug!(\"{entity:?} has no Health\");\n    }\n    Err(e) => return Err(e.into()),\n}","handlingStrategy":"validation","validationCode":"let type_id = TypeId::of::<T>();\nif let Some(cid) = world.get_component_id(type_id) {\n    if world.get_by_id(entity, cid).is_some() {\n        let c = world.get_reflect(entity, type_id);\n        // ...\n    }\n}","typeGuard":null,"tryCatchPattern":"match world.get_reflect(entity, TypeId::of::<T>()) {\n    Ok(Some(c)) => { /* present */ }\n    Ok(None) => { /* entity lacks component — normal case */ }\n    Err(GetComponentReflectError::EntityDoesNotHaveComponent { entity, .. }) => {\n        debug!(\"{entity:?} lacks component\");\n    }\n    Err(e) => { /* ... */ }\n}","preventionTips":["Scope reflective walks with Query<(Entity, &T)> so presence is guaranteed by the query filter.","Handle the EntityDoesNotHaveComponent variant as ordinary control flow, not an exceptional failure.","After removal commands, flush before reflecting if you expect removals to have taken effect."],"tags":["bevy","ecs","reflect","component","entity","query-mismatch"],"backgroundTag":"component-not-found","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}