{"record":{"id":"ef3659aaa7e25327","repo":"bevyengine/bevy","slug":"view-entity-not-found","errorCode":null,"errorMessage":"View entity not found","messagePattern":"View entity not found","errorType":"exception","errorClass":"DrawError","httpStatus":null,"severity":"error","filePath":"crates/bevy_render/src/render_phase/draw.rs","lineNumber":50,"sourceCode":"    fn prepare(&mut self, world: &'_ World) {}\n\n    /// Draws a [`PhaseItem`] by issuing zero or more `draw` calls via the [`TrackedRenderPass`].\n    fn draw<'w>(\n        &mut self,\n        world: &'w World,\n        pass: &mut TrackedRenderPass<'w>,\n        view: Entity,\n        item: &P,\n    ) -> Result<(), DrawError>;\n}\n\n#[derive(Error, Debug, PartialEq, Eq)]\npub enum DrawError {\n    #[error(\"Failed to execute render command {0:?}\")]\n    RenderCommandFailure(&'static str),\n    #[error(\"Failed to get execute view query\")]\n    InvalidViewQuery,\n    #[error(\"View entity not found\")]\n    ViewEntityNotFound,\n}\n\n/// Stores all [`Draw`] functions for the [`PhaseItem`] type.\n///\n/// For retrieval, the [`Draw`] functions are mapped to their respective [`TypeId`]s.\npub struct DrawFunctionsInternal<P: PhaseItem> {\n    pub draw_functions: Vec<Box<dyn Draw<P>>>,\n    pub indices: TypeIdHashMap<DrawFunctionId>,\n}\n\nimpl<P: PhaseItem> DrawFunctionsInternal<P> {\n    /// Prepares all draw function. This is called once and only once before the phase begins.\n    pub fn prepare(&mut self, world: &World) {\n        for function in &mut self.draw_functions {\n            function.prepare(world);\n        }\n    }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/src/render_phase/draw.rs#L32-L68","documentation":"DrawError::ViewEntityNotFound is returned by RenderCommandState::draw (draw.rs:333) when the view entity passed to RenderPhase::render/render_range is not spawned in the render world (QueryEntityError::NotSpawned from the command's ViewQuery). The entity handle used for drawing refers to an entity that does not exist.","triggerScenarios":"Calling render_phase.render(&mut pass, world, view_entity) with a view Entity that was despawned, never existed in the render world, or is a main-world entity handle used against the render world; stale view handles cached across frames.","commonSituations":"Cameras despawned between extraction and render; custom render nodes caching the view entity from a previous frame; systems running during app teardown or after render-world clearing; mixing up main-world and render-world entity ids.","solutions":["Check the entity exists in the render world before rendering (world.entities().contains(view)).","Do not cache view entities across frames; re-query the view each render.","Perform camera/entity despawns via Commands in the main schedule rather than during extract/render.","Catch the error and skip the frame instead of propagating a hard failure."],"exampleFix":"// before\nrender_phase.render(&mut render_pass, &render_world, cached_view_entity)?;\n\n// after\nif !render_world.entities().contains(cached_view_entity) {\n    warn!(\"view entity {cached_view_entity:?} gone; skipping frame\");\n    return Ok(());\n}\nlet _ = render_phase.render(&mut render_pass, &render_world, cached_view_entity);","handlingStrategy":"validation","validationCode":"if !render_world.entities().contains(view_entity) {\n    // despawned or never existed in the render world\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"match render_phase.render(&mut pass, &render_world, view) {\n    Err(DrawError::ViewEntityNotFound) => warn!(\"view {view:?} despawned before render\"),\n    Err(other) => error!(\"{other:?}\"),\n    Ok(()) => {}\n}","preventionTips":["Never cache view entities across frames; re-resolve them each render.","Despawn cameras via Commands in the main schedule, not during extract/render.","Be explicit about which world an entity id belongs to (main vs render)."],"tags":["bevy","ecs","entity","view","render"],"backgroundTag":"entity-not-found","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"}