bevyengine/bevy · error · GetEntityMutByIdError::InfoNotFound

the `ComponentInfo` could not be found

Error message

the `ComponentInfo` could not be found

What it means

GetEntityMutByIdError::InfoNotFound is returned by UnsafeEntityCell::get_mut_by_id when the ComponentId you pass has no ComponentInfo in the world's component registry — i.e. the id was never allocated by THIS world. ComponentIds are world-local indices; using one from another World, or an id created before a world reset (clear_all reallocates ids), yields this error instead of a pointer.

Source

Thrown at crates/bevy_ecs/src/world/unsafe_world_cell.rs:1222

    }

    /// Returns the [`Tick`] at which this entity has been spawned.
    pub fn spawn_tick(self) -> Tick {
        // SAFETY: UnsafeEntityCell is only constructed for living entities and offers no despawn method
        unsafe {
            self.world()
                .entities()
                .entity_get_spawned_or_despawned_unchecked(self.entity)
                .1
        }
    }
}

/// Error that may be returned when calling [`UnsafeEntityCell::get_mut_by_id`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum GetEntityMutByIdError {
    /// The [`ComponentInfo`](crate::component::ComponentInfo) could not be found.
    #[error("the `ComponentInfo` could not be found")]
    InfoNotFound,
    /// The [`Component`] is immutable. Creating a mutable reference violates its
    /// invariants.
    #[error("the `Component` is immutable")]
    ComponentIsImmutable,
    /// This [`Entity`] does not have the desired [`Component`].
    #[error("the `Component` could not be found")]
    ComponentNotFound,
}

impl<'w> UnsafeWorldCell<'w> {
    #[inline]
    /// # Safety
    /// - the returned `Table` is only used in ways that this [`UnsafeWorldCell`] has permission for.
    /// - the returned `Table` is only used in ways that would not conflict with any existing borrows of world data.
    unsafe fn fetch_table(self, location: EntityLocation) -> Option<&'w Table> {
        // SAFETY:
        // - caller ensures returned data is not misused and we have not created any borrows of component/resource data

View on GitHub (pinned to 396ca72708)

Solutions

  1. Resolve ids per-world: call world.components().component_id::<T>() (or register_component::<T>()) on the same World whose cell you hold.
  2. Invalidate cached ComponentIds whenever the World is cleared/rebuilt; treat them as world-scoped, not global.
  3. Validate before the unsafe call: world.components().get_info(id).is_some(); this is the exact condition that produces InfoNotFound.
  4. Handle the Result by matching GetEntityMutByIdError instead of unwrapping, since this API is already fallible.

Example fix

// before
let ptr = cell.get_mut_by_id(cached_id).unwrap(); // InfoNotFound: id from another world

// after
let id = cell.world().components().component_id::<T>()
    .expect("component registered in this world");
match cell.get_mut_by_id(id) {
    Ok(Some(mut c)) => { /* ... */ }
    Ok(None) => {}
    Err(GetEntityMutByIdError::InfoNotFound) => debug!("unknown ComponentId {id:?}"),
    Err(e) => debug!("{e}"),
}
Defensive patterns

Strategy: try-catch

Validate before calling

let valid = world
    .components()
    .get_info(component_id)
    .is_some();
if !valid { /* resolve id from this world: */
    let component_id = world.components().component_id::<T>().unwrap();
}

Try / catch

match cell.get_mut_by_id(component_id) {
    Ok(value) => { /* ... */ }
    Err(GetEntityMutByIdError::InfoNotFound) => {
        // id not from this world: re-resolve and retry once, or skip
    }
    Err(e) => { /* ... */ }
}

Prevention

When it happens

Trigger: Calling unsafe_entity_cell.get_mut_by_id(component_id) with a ComponentId captured from a different World (main vs render sub-world), from a previous run of a reset World, or an id you constructed/hand-indexed rather than obtained via world.components().component_id::<T>() / get_component_id().

Common situations: Unsafe/Schedule-internal code or performance-critical per-component access where ids are cached for speed; multi-world extraction pipelines copying ids between worlds; long-lived caches of ComponentId surviving world rebuilds in editor workflows.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/ebba54b68e2895fc. Report an issue: GitHub.