bevyengine/bevy · error
resource does not exist: {}
Error message
resource does not exist: {} What it means
World::resource_scope::<R, _> temporarily removes the resource R, gives your closure exclusive (&mut World, Mut<R>) access, and re-inserts R afterwards. The wrapper panics via try_resource_scope(...).unwrap_or_else when R does not exist in the World at call time, printing the type name. It is the standard way to mutate a resource and the world simultaneously, so it fails loudly when the resource was never initialized.
Source
Thrown at crates/bevy_ecs/src/world/mod.rs:2795
/// world.insert_resource(A(1));
/// let entity = world.spawn(B(1)).id();
///
/// world.resource_scope(|world, mut a: Mut<A>| {
/// let b = world.get_mut::<B>(entity).unwrap();
/// a.0 += b.0;
/// });
/// assert_eq!(world.get_resource::<A>().unwrap().0, 2);
/// ```
///
/// # Note
///
/// If the world's resource metadata is cleared within the scope, such as by calling
/// [`World::clear_resources`] or [`World::clear_all`], the resource will *not* be re-inserted
/// at the end of the scope.
#[track_caller]
pub fn resource_scope<R: Resource, U>(&mut self, f: impl FnOnce(&mut World, Mut<R>) -> U) -> U {
self.try_resource_scope(f)
.unwrap_or_else(|| panic!("resource does not exist: {}", DebugName::type_name::<R>()))
}
/// Temporarily removes the requested resource from this [`World`] if it exists, runs custom user code,
/// then re-adds the resource before returning. Returns `None` if the resource does not exist in this [`World`].
///
/// This enables safe simultaneous mutable access to both a resource and the rest of the [`World`].
/// For more complex access patterns, consider using [`SystemState`](crate::system::SystemState).
///
/// See also [`resource_scope`](Self::resource_scope).
///
/// # Note
///
/// If the world's resource metadata is cleared within the scope, such as by calling
/// [`World::clear_resources`] or [`World::clear_all`], the resource will *not* be re-inserted
/// at the end of the scope.
pub fn try_resource_scope<R: Resource, U>(
&mut self,
f: impl FnOnce(&mut World, Mut<R>) -> U,View on GitHub (pinned to 396ca72708)
Solutions
- Initialize the resource first: app.init_resource::<R>() (needs Default) or app.insert_resource(R { ... }).
- Add the plugin that provides R, or fix plugin ordering so it builds before your system runs.
- For optional resources use world.try_resource_scope(...) which returns Option<U> instead of panicking.
- If you cleared resources intentionally (clear_resources/clear_all inside a scope), remember they are NOT re-inserted and re-init afterwards.
Example fix
// before
world.resource_scope(|world, mut assets: Mut<MyAssets>| { /* ... */ }); // panics
// after
world.init_resource::<MyAssets>();
world.resource_scope(|world, mut assets: Mut<MyAssets>| { /* ... */ });
// or, optional style:
let result = world.try_resource_scope(|world, mut assets: Mut<MyAssets>| assets.count); Defensive patterns
Strategy: validation
Validate before calling
if world.get_resource::<R>().is_some() {
world.resource_scope(|w, mut r: Mut<R>| { /* ... */ });
} else {
world.init_resource::<R>();
} Try / catch
let out = world.try_resource_scope(|w, mut r: Mut<R>| {
// ...
}); // Option<U>: None means resource absent Prevention
- init_resource every resource you will scope, in plugin build().
- Remember clear_resources/clear_all inside a scope will not re-insert the resource afterwards.
- Use try_resource_scope when a resource is legitimately optional.
When it happens
Trigger: Calling world.resource_scope(|w, mut r: Mut<R>| ...) before app.init_resource::<R>() / insert_resource(...) ran; calling it inside a schedule that executes before the resource's plugin (e.g. in First while the plugin inserts in PreStartup); calling it on a World where the resource was cleared with clear_resources()/clear_all(); using it as a system via IntoSystem with ResMut after the resource was removed.
Common situations: Forgetting to init a custom State/NextState-like resource; running tests with MinimalPlugins that omit the plugin owning the resource; ordering mistakes where a Startup system runs after a schedule that already used resource_scope; plugin refactor renaming the resource type so a different (uninitialized) type is requested.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Resource `{}` was inserted during a call to World::resource_
- Encountered a mismatched World. This SystemState was created
- ParamSet parameter validation failed: {err}
- Cannot call `ReflectComponent::reflect_mut` on component {na
- Cannot call `ReflectComponent::reflect_unchecked_mut` on com
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/8d9a61ec6d089675.
Report an issue: GitHub.