bevyengine/bevy · error · SpawnError

The entity can not be spawned as it already has a location.

Error message

The entity can not be spawned as it already has a location.

What it means

thiserror Display message for SpawnError::AlreadySpawned: the spawn was attempted for an Entity whose index already has a live location in the Entities allocator (meta.location is Some). Spawning the same reserved id twice triggers this variant.

Source

Thrown at crates/bevy_ecs/src/entity/mod.rs:1118

            .count() as u32
    }

    /// Returns true if there are any entity indices currently spawned.
    /// See the module docs for a more precise explanation of what spawning means.
    pub fn any_spawned(&self) -> bool {
        self.meta.iter().any(|meta| meta.location.is_some())
    }
}

/// An error that occurs when a specified [`Entity`] can not be spawned.
#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Eq)]
pub enum SpawnError {
    /// The [`Entity`] to spawn was invalid.
    /// It probably had the wrong generation or was created erroneously.
    #[error("Invalid id: {0}")]
    Invalid(InvalidEntityError),
    /// The [`Entity`] to spawn was already spawned.
    #[error("The entity can not be spawned as it already has a location.")]
    AlreadySpawned,
}

/// An error that occurs when a specified [`Entity`] does not exist in the entity id space.
/// See [module](crate::entity) docs for more about entity validity.
#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Eq)]
#[error(
    "The entity with ID {entity} is invalid; its index now has generation {current_generation}."
)]
pub struct InvalidEntityError {
    /// The entity's ID.
    pub entity: Entity,
    /// The generation of the [`EntityIndex`], which did not match the requested entity.
    pub current_generation: EntityGeneration,
}

/// An error that occurs when a specified [`Entity`] is certain to be valid and is expected to be spawned but is not spawned yet.
/// This includes when an [`EntityIndex`] is requested but is not spawned, since each index always corresponds to exactly one valid entity.

View on GitHub (pinned to 396ca72708)

Solutions

  1. Spawn a fresh entity instead of reusing an already-spawned id
  2. Check Entities::contains before attempting to spawn a reserved id
  3. Review command flush ordering if the same entity is spawned by two systems
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/bevy_ecs/src/entity/mod.rs:1118 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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