bevyengine/bevy · error · EntityNotSpawnedError
Entity despawned: {0} Note that interacting with a despawned
Error message
Entity despawned: {0}
Note that interacting with a despawned entity is the most common cause of this error but there are others What it means
Display/label message for EntityValidButNotSpawnedError: the entity id itself is valid (correct generation) but its index currently has no live location — it was despawned. The note clarifies that although despawn is the most common cause, any interaction with a freed-but-valid index can surface this error. The Display body can name the despawning location when track_location is enabled.
Source
Thrown at crates/bevy_ecs/src/entity/mod.rs:1163
impl fmt::Display for EntityValidButNotSpawnedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let entity = self.entity;
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 {View on GitHub (pinned to 396ca72708)
Solutions
- Treat the entity as gone: stop using the handle and re-acquire it if it is respawned
- Guard accesses with query results or Entities::contains instead of assuming liveness
- Enable the track_location feature during debugging to learn where the entity was despawned
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/src/entity/mod.rs:1163 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/cf956252837a7754.
Report an issue: GitHub.