bevyengine/bevy · error · EntityNotSpawnedError
Entity not yet spawned: {0} Note that interacting with a not
Error message
Entity not yet spawned: {0}
Note that interacting with a not-yet-spawned entity is the most common cause of this error but there are others What it means
Label message for the not-yet-spawned flavor of entity errors: the id is reserved/valid but its index has never been given a location in this World (e.g. an Entity obtained from reserve_entity or commands before the spawn is flushed). The note warns that any interaction with such an unspawned index, not only spawn misuse, produces this error.
Source
Thrown at crates/bevy_ecs/src/entity/mod.rs:1166
match self.location.into_option() {
Some(location) => write!(f, "The entity with ID {entity} is not spawned; its index was last despawned by {location}."),
None => write!(
f,
"The entity with ID {entity} is not spawned; enable `track_location` feature for more details."
),
}
}
}
/// An error that occurs when a specified [`Entity`] is expected to be valid and spawned but is not.
/// Represents an error of either [`InvalidEntityError`] (when the entity is invalid) or [`EntityValidButNotSpawnedError`] (when the [`EntityGeneration`] is correct but the [`EntityIndex`] is not spawned).
#[derive(thiserror::Error, Copy, Clone, Debug, Eq, PartialEq)]
pub enum EntityNotSpawnedError {
/// The entity was invalid.
#[error("Entity despawned: {0}\nNote that interacting with a despawned entity is the most common cause of this error but there are others")]
Invalid(#[from] InvalidEntityError),
/// The entity was valid but was not spawned.
#[error("Entity not yet spawned: {0}\nNote that interacting with a not-yet-spawned entity is the most common cause of this error but there are others")]
ValidButNotSpawned(#[from] EntityValidButNotSpawnedError),
}
impl EntityNotSpawnedError {
/// The entity that did not exist or was not spawned.
pub fn entity(&self) -> Entity {
match self {
EntityNotSpawnedError::Invalid(err) => err.entity,
EntityNotSpawnedError::ValidButNotSpawned(err) => err.entity,
}
}
}
#[derive(Copy, Clone, Debug)]
struct EntityMeta {
/// The current [`EntityGeneration`] of the [`EntityIndex`].
generation: EntityGeneration,
/// The current location of the [`EntityIndex`].View on GitHub (pinned to 396ca72708)
Solutions
- Ensure spawn commands are flushed (or use world.flush_commands) before touching reserved entities
- Pass reserved Entity ids only where spawning will complete, such as spawn_with commands
- Re-query the entity after the frame's command flush to confirm it is live
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/src/entity/mod.rs:1166 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/5f083cc966393d4b.
Report an issue: GitHub.