{"record":{"id":"cf956252837a7754","repo":"bevyengine/bevy","slug":"entity-despawned-0-note-that-interacting-with-a","errorCode":null,"errorMessage":"Entity despawned: {0}\nNote that interacting with a despawned entity is the most common cause of this error but there are others","messagePattern":"Entity despawned: (.+?)\nNote that interacting with a despawned entity is the most common cause of this error but there are others","errorType":"exception","errorClass":"EntityNotSpawnedError","httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/entity/mod.rs","lineNumber":1163,"sourceCode":"impl fmt::Display for EntityValidButNotSpawnedError {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        let entity = self.entity;\n        match self.location.into_option() {\n            Some(location) => write!(f, \"The entity with ID {entity} is not spawned; its index was last despawned by {location}.\"),\n            None => write!(\n                f,\n                \"The entity with ID {entity} is not spawned; enable `track_location` feature for more details.\"\n            ),\n        }\n    }\n}\n\n/// An error that occurs when a specified [`Entity`] is expected to be valid and spawned but is not.\n/// Represents an error of either [`InvalidEntityError`] (when the entity is invalid) or [`EntityValidButNotSpawnedError`] (when the [`EntityGeneration`] is correct but the [`EntityIndex`] is not spawned).\n#[derive(thiserror::Error, Copy, Clone, Debug, Eq, PartialEq)]\npub enum EntityNotSpawnedError {\n    /// The entity was invalid.\n    #[error(\"Entity despawned: {0}\\nNote that interacting with a despawned entity is the most common cause of this error but there are others\")]\n    Invalid(#[from] InvalidEntityError),\n    /// The entity was valid but was not spawned.\n    #[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\")]\n    ValidButNotSpawned(#[from] EntityValidButNotSpawnedError),\n}\n\nimpl EntityNotSpawnedError {\n    /// The entity that did not exist or was not spawned.\n    pub fn entity(&self) -> Entity {\n        match self {\n            EntityNotSpawnedError::Invalid(err) => err.entity,\n            EntityNotSpawnedError::ValidButNotSpawned(err) => err.entity,\n        }\n    }\n}\n\n#[derive(Copy, Clone, Debug)]\nstruct EntityMeta {","sourceCodeStart":1145,"sourceCodeEnd":1181,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/entity/mod.rs#L1145-L1181","documentation":"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.","triggerScenarios":"Thrown at crates/bevy_ecs/src/entity/mod.rs:1163 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}