bevyengine/bevy · error · QueryEntityError

{0}

Error message

{0}

What it means

thiserror Display for QueryEntityError::NotSpawned: the transparently wrapped EntityNotSpawnedError indicates the Entity passed to Query::get is not currently spawned in the world (invalid generation, despawned, or never spawned). The inner error's own Display is shown via {0}.

Source

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

use bevy_utils::prelude::DebugName;

use crate::{
    archetype::ArchetypeId,
    entity::{Entity, EntityNotSpawnedError},
};

/// An error that occurs when retrieving a specific [`Entity`]'s query result from [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState).
// TODO: return the type_name as part of this error
#[derive(thiserror::Error, Clone, Copy, Debug, PartialEq, Eq)]
pub enum QueryEntityError {
    /// The given [`Entity`]'s components do not match the query.
    ///
    /// Either it does not have a requested component, or it has a component which the query filters out.
    #[error("The query does not match entity {0}")]
    QueryDoesNotMatch(Entity, ArchetypeId),
    /// The given [`Entity`] is not spawned.
    #[error("{0}")]
    NotSpawned(#[from] EntityNotSpawnedError),
    /// The [`Entity`] was requested mutably more than once.
    ///
    /// See [`Query::get_many_mut`](crate::system::Query::get_many_mut) for an example.
    #[error("The entity with ID {0} was requested mutably more than once")]
    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),

View on GitHub (pinned to 396ca72708)

Solutions

  1. Re-fetch the entity id after the despawn/spawn cycle that invalidated it
  2. Check Entities::contains(entity) before querying
  3. Flush pending commands so recently spawned entities are visible to the query
Defensive patterns

Strategy: validation

When it happens

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