{"record":{"id":"224b0944c6705845","repo":"bevyengine/bevy","slug":"encountered-a-mismatched-world-this-querystate-wa","errorCode":null,"errorMessage":"Encountered a mismatched World. This QueryState was created from {this:?}, but a method was called using {other:?}.","messagePattern":"Encountered a mismatched World\\. This QueryState was created from (.+?), but a method was called using (.+?)\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/query/state.rs","lineNumber":627,"sourceCode":"            }\n            self.archetype_generation = world.archetypes().generation();\n        }\n    }\n\n    /// # Panics\n    ///\n    /// If `world_id` does not match the [`World`] used to call `QueryState::new` for this instance.\n    ///\n    /// Many unsafe query methods require the world to match for soundness. This function is the easiest\n    /// way of ensuring that it matches.\n    #[inline]\n    #[track_caller]\n    pub fn validate_world(&self, world_id: WorldId) {\n        #[inline(never)]\n        #[track_caller]\n        #[cold]\n        fn panic_mismatched(this: WorldId, other: WorldId) -> ! {\n            panic!(\"Encountered a mismatched World. This QueryState was created from {this:?}, but a method was called using {other:?}.\");\n        }\n\n        if self.world_id != world_id {\n            panic_mismatched(self.world_id, world_id);\n        }\n    }\n\n    /// Update the current [`QueryState`] with information from the provided [`Archetype`]\n    /// (if applicable, i.e. if the archetype has any intersecting [`ComponentId`] with the current [`QueryState`]).\n    ///\n    /// # Safety\n    /// `archetype` must be from the `World` this state was initialized from.\n    pub unsafe fn new_archetype(&mut self, archetype: &Archetype) {\n        if D::matches_component_set(&self.fetch_state, &|id| archetype.contains(id))\n            && F::matches_component_set(&self.filter_state, &|id| archetype.contains(id))\n            && self.matches_component_set(&|id| archetype.contains(id))\n        {\n            let archetype_index = archetype.id().index();","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/query/state.rs#L609-L645","documentation":"Panic from QueryState::validate_world's cold helper: the WorldId passed in differs from the world this QueryState was constructed/initialized against. Many unsafe query methods rely on world identity for soundness (component layouts must match initialization), so this mismatch guard makes the bug loud before unsound access.","triggerScenarios":"Thrown at crates/bevy_ecs/src/query/state.rs:627 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create a new QueryState per World (QueryState::new / world.query) instead of reusing one across worlds","Pass the same world instance (or its id) that initialized the state","Call validate_world early to catch reuse mistakes in tests"],"exampleFix":null,"handlingStrategy":"validation","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-14T05:17:10.506Z"}