bevyengine/bevy · error

Encountered a mismatched World. This QueryState was created

Error message

Encountered a mismatched World. This QueryState was created from {this:?}, but a method was called using {other:?}.

What it means

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.

Source

Thrown at crates/bevy_ecs/src/query/state.rs:627

            }
            self.archetype_generation = world.archetypes().generation();
        }
    }

    /// # Panics
    ///
    /// If `world_id` does not match the [`World`] used to call `QueryState::new` for this instance.
    ///
    /// Many unsafe query methods require the world to match for soundness. This function is the easiest
    /// way of ensuring that it matches.
    #[inline]
    #[track_caller]
    pub fn validate_world(&self, world_id: WorldId) {
        #[inline(never)]
        #[track_caller]
        #[cold]
        fn panic_mismatched(this: WorldId, other: WorldId) -> ! {
            panic!("Encountered a mismatched World. This QueryState was created from {this:?}, but a method was called using {other:?}.");
        }

        if self.world_id != world_id {
            panic_mismatched(self.world_id, world_id);
        }
    }

    /// Update the current [`QueryState`] with information from the provided [`Archetype`]
    /// (if applicable, i.e. if the archetype has any intersecting [`ComponentId`] with the current [`QueryState`]).
    ///
    /// # Safety
    /// `archetype` must be from the `World` this state was initialized from.
    pub unsafe fn new_archetype(&mut self, archetype: &Archetype) {
        if D::matches_component_set(&self.fetch_state, &|id| archetype.contains(id))
            && F::matches_component_set(&self.filter_state, &|id| archetype.contains(id))
            && self.matches_component_set(&|id| archetype.contains(id))
        {
            let archetype_index = archetype.id().index();

View on GitHub (pinned to 396ca72708)

Solutions

  1. Create a new QueryState per World (QueryState::new / world.query) instead of reusing one across worlds
  2. Pass the same world instance (or its id) that initialized the state
  3. Call validate_world early to catch reuse mistakes in tests
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/bevy_ecs/src/query/state.rs:627 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/224b0944c6705845. Report an issue: GitHub.