{"record":{"id":"8f0fbbd2ec6d6864","repo":"bevyengine/bevy","slug":"query-does-not-match-the-current-entity","errorCode":null,"errorMessage":"Query does not match the current entity","messagePattern":"Query does not match the current entity","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/world/entity_access/entity_ref.rs","lineNumber":287,"sourceCode":"    #[inline]\n    pub fn get_by_id<F: DynamicComponentFetch>(\n        &self,\n        component_ids: F,\n    ) -> Result<F::Ref<'w>, EntityComponentError> {\n        // SAFETY: We have read-only access to all components of this entity.\n        unsafe { component_ids.fetch_ref(self.cell) }\n    }\n\n    /// Returns read-only components for the current entity that match the query `Q`.\n    ///\n    /// # Panics\n    ///\n    /// If the entity does not have the components required by the query `Q`.\n    pub fn components<Q: ReadOnlyQueryData + ReleaseStateQueryData + SingleEntityQueryData>(\n        &self,\n    ) -> Q::Item<'w, 'static> {\n        self.get_components::<Q>()\n            .expect(\"Query does not match the current entity\")\n    }\n\n    /// Returns read-only components for the current entity that match the query `Q`,\n    /// or `None` if the entity does not have the components required by the query `Q`.\n    pub fn get_components<Q: ReadOnlyQueryData + ReleaseStateQueryData + SingleEntityQueryData>(\n        &self,\n    ) -> Result<Q::Item<'w, 'static>, QueryAccessError> {\n        // SAFETY:\n        // - We have read-only access to all components of this entity.\n        // - The query is read-only, and read-only references cannot have conflicts.\n        unsafe { self.cell.get_components::<Q>() }\n    }\n\n    /// Returns the source code location from which this entity has been spawned.\n    pub fn spawned_by(&self) -> MaybeLocation {\n        self.cell.spawned_by()\n    }\n","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/world/entity_access/entity_ref.rs#L269-L305","documentation":"Panics in EntityRef::components<Q> when the entity does not satisfy the query Q (e.g. a required component or filter is missing), so the query has no match for this particular entity.","triggerScenarios":"Thrown at crates/bevy_ecs/src/world/entity_access/entity_ref.rs:287 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use get_components::<Q>() which returns an Option instead of panicking","Check entity.contains::<T>() / matches the filter before calling","Ensure the component is actually inserted on the entity beforehand"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}