bevyengine/bevy · error
Expected {after:?} to exist
Error message
Expected {after:?} to exist What it means
`RenderScheduleOrder` holds the ordered list of schedule labels the RenderApp executes (starting from First and Render in the default setup). `insert_after(after, schedule)` panics with "Expected {after:?} to exist" when the anchor label is not in that list — insertion is only possible relative to an already-present schedule.
Source
Thrown at crates/bevy_render/src/lib.rs:302
pub labels: Vec<InternedScheduleLabel>,
}
impl Default for RenderScheduleOrder {
fn default() -> Self {
Self {
labels: vec![First.intern(), Render.intern()],
}
}
}
impl RenderScheduleOrder {
/// Adds the given `schedule` after the `after` schedule
pub fn insert_after(&mut self, after: impl ScheduleLabel, schedule: impl ScheduleLabel) {
let index = self
.labels
.iter()
.position(|current| (**current).eq(&after))
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
self.labels.insert(index + 1, schedule.intern());
}
/// Adds the given `schedule` before the `before` schedule
pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {
let index = self
.labels
.iter()
.position(|current| (**current).eq(&before))
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
self.labels.insert(index, schedule.intern());
}
}
/// The main render schedule.
///
/// See also [`RenderGraph`] for more details.
#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)]View on GitHub (pinned to 396ca72708)
Solutions
- Insert relative to a label guaranteed to exist, e.g. `Render` or `First`
- Ensure the anchor schedule was inserted earlier (inspect `order.labels`)
- Insert your schedule standalone first, then reorder it relative to known labels
Example fix
// before order.insert_after(MyCustomSchedule, MyNewSchedule); // MyCustomSchedule not inserted yet // after order.insert_after(Render, MyNewSchedule); // or insert MyCustomSchedule first
Defensive patterns
Strategy: validation
Validate before calling
// RenderScheduleOrder stores Box<dyn ScheduleLabel>
let exists = order.labels.iter().any(|l| (**l).eq(&MySchedule));
if exists {
order.insert_after(MySchedule, MyNewSchedule);
} else {
order.insert_after(Render, MyNewSchedule); // safe anchor
} Prevention
- Anchor insert_after calls to Render or First, which always exist
- Insert custom labels before other plugins order against them
- Log order.labels once at startup to see the actual order
When it happens
Trigger: Calling `render_schedule_order.insert_after(MySchedule, NewSchedule)` when `MySchedule` was never inserted into the order, was removed, or the label type is misspelled/different.
Common situations: Plugins inserting a custom sub-schedule relative to their own label before that label is registered; hand-written ordering code using the wrong label type.
Related errors
- Expected {before:?} to exist
- DependencySort
- FlatDependencySort
- CrossDependency
- SetsHaveOrderButIntersect
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/a60f8376ac7970eb.
Report an issue: GitHub.