bevyengine/bevy · error · DrawError
Failed to get execute view query
Error message
Failed to get execute view query
What it means
DrawError::InvalidViewQuery is returned by RenderCommandState::draw (draw.rs:336) when fetching the view entity with the RenderCommand's ViewQuery fails with QueryDoesNotMatch or AliasedMutability. The view entity is alive in the render world but does not satisfy the component/filter requirements the command declared, so the command cannot run.
Source
Thrown at crates/bevy_render/src/render_phase/draw.rs:48
reason = "The parameters here are intentionally unused by the default implementation; however, putting underscores here will result in the underscores being copied by rust-analyzer's tab completion."
)]
fn prepare(&mut self, world: &'_ World) {}
/// Draws a [`PhaseItem`] by issuing zero or more `draw` calls via the [`TrackedRenderPass`].
fn draw<'w>(
&mut self,
world: &'w World,
pass: &mut TrackedRenderPass<'w>,
view: Entity,
item: &P,
) -> Result<(), DrawError>;
}
#[derive(Error, Debug, PartialEq, Eq)]
pub enum DrawError {
#[error("Failed to execute render command {0:?}")]
RenderCommandFailure(&'static str),
#[error("Failed to get execute view query")]
InvalidViewQuery,
#[error("View entity not found")]
ViewEntityNotFound,
}
/// Stores all [`Draw`] functions for the [`PhaseItem`] type.
///
/// For retrieval, the [`Draw`] functions are mapped to their respective [`TypeId`]s.
pub struct DrawFunctionsInternal<P: PhaseItem> {
pub draw_functions: Vec<Box<dyn Draw<P>>>,
pub indices: TypeIdHashMap<DrawFunctionId>,
}
impl<P: PhaseItem> DrawFunctionsInternal<P> {
/// Prepares all draw function. This is called once and only once before the phase begins.
pub fn prepare(&mut self, world: &World) {
for function in &mut self.draw_functions {
function.prepare(world);View on GitHub (pinned to 396ca72708)
Solutions
- Make optional components Option<&T> / Option<&mut T> in the ViewQuery so views lacking them still match.
- Ensure the required component is actually extracted to the render world (add it in your extract system or via RequiredComponents on the extracted view).
- Do not share one command between phases whose views differ; queue a per-phase command whose ViewQuery matches that phase's views.
- Handle the error by skipping the view for the frame while logging which command/view mismatched.
Example fix
// before: view query requires a component only some views have type ViewQuery = (&'static ExtractedView, &'static CustomViewData); // after: make it optional so non-matching views still pass the query // (handle None inside render()) type ViewQuery = (&'static ExtractedView, Option<&'static CustomViewData>);
Defensive patterns
Strategy: validation
Validate before calling
// Run the same view query the command will use, before rendering:
let view_ok = view_query.get_manual(&render_world, view_entity).is_ok();
if !view_ok {
warn!("view {view_entity:?} does not match ViewQuery; skipping");
} Try / catch
match render_phase.render(&mut pass, &world, view) {
Err(DrawError::InvalidViewQuery) => warn!("view query mismatch for {view:?}"),
Err(other) => error!("{other:?}"),
Ok(()) => {}
} Prevention
- Make ViewQuery components Option<&T> unless every view in that phase carries them.
- Extract every component your ViewQuery requires into the render world.
- Do not share a single RenderCommand between view types with different component sets.
When it happens
Trigger: A RenderCommand's associated ViewQuery requires components (e.g. ExtractedView, ViewUniformOffset, or a custom view component) that the view entity in the render world lacks, or a filter that excludes that view; self.view.get_manual(world, view) returns QueryDoesNotMatch during RenderPhase::render.
Common situations: Custom render commands shared between view types (main camera vs shadow vs prepass views) where only some carry the required component; plugins that forget to extract their view component into the render world; adding a component to ViewQuery that is attached to the camera in the main world but never extracted.
Related errors
- View entity not found
- Union types are not supported yet.
- Expected a Template type path
- Can only derive VariantDefaults for enums
- Cannot call `ReflectComponent::reflect_mut` on component {na
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/126ef79864d9bbf3.
Report an issue: GitHub.