bevyengine/bevy · error · QueryNotDenseError

Cannot contiguously iterate non-dense query {0}

Error message

Cannot contiguously iterate non-dense query {0}

What it means

Panic message from update_component_access in query filter codegen (e.g. Added<T>/Changed<T> filters): registering the filter's component access found the component already accessed exclusively (mutably) elsewhere in the same query, while the filter needs shared (read) access — an unsound access conflict detected while building FilteredAccess.

Source

Thrown at crates/bevy_ecs/src/query/error.rs:42

    AliasedMutability(Entity),
}

/// An error that occurs when evaluating a [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState) as a single expected result via
/// [`single`](crate::system::Query::single) or [`single_mut`](crate::system::Query::single_mut).
#[derive(Debug, thiserror::Error)]
pub enum QuerySingleError {
    /// No entity fits the query.
    #[error("No entities fit the query {0}")]
    NoEntities(DebugName),
    /// Multiple entities fit the query.
    #[error("Multiple entities fit the query {0}")]
    MultipleEntities(DebugName),
}

/// An error that occurs when creating a contiguous iterator from a non-dense [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState) via
/// [`contiguous_iter`](crate::system::Query::contiguous_iter) or [`contiguous_iter_mut`](crate::system::Query::contiguous_iter_mut).
#[derive(Debug, thiserror::Error)]
#[error("Cannot contiguously iterate non-dense query {0}")]
pub struct QueryNotDenseError(pub DebugName);

#[cfg(test)]
mod test {
    use crate::{prelude::World, query::QueryEntityError};
    use bevy_ecs_macros::Component;

    #[test]
    fn query_does_not_match() {
        let mut world = World::new();

        #[derive(Component)]
        struct Present1;
        #[derive(Component)]
        struct Present2;
        #[derive(Component, Debug, PartialEq)]
        struct NotPresent;

View on GitHub (pinned to 396ca72708)

Solutions

  1. Split conflicting accesses into separate systems
  2. Use ParamSet to sequence the mutable and read-only accesses
  3. Add Without<T> / disjoint filters so the two accesses never touch the same entity
  4. Drop the mutable access if read-only suffices
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/bevy_ecs/src/query/error.rs:42 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/063c47df338bcd3a. Report an issue: GitHub.