pub fn despawn(&self, entity: Entity) -> Result<(), NoSuchEntity> {
        if !self.access.is_entity_overridden(entity) {
            // if we don't have override data, create it before proceeding
            let override_data = EntityOverrideData::from_world(&self.world, entity)?;

            self.override_data
                .borrow_mut()
                .insert(entity, EntityOverride::Changed(override_data));
            self.access.set_entity_overridden(entity);
        }
        let mut override_map = self.override_data.borrow_mut();
        let entity_override = override_map
            .get_mut(&entity)
            .expect("override data not present despite entity being marked as overriden");
        match entity_override {
            EntityOverride::Deleted => return Err(NoSuchEntity),
            EntityOverride::Changed(data) => unsafe {
                for ty in &data.types {
                    if self.access.has_active_borrows(entity, ty.id()) {
                        panic!("Component {} on entity {:?} has an active borrow when despawning entity", ty.name().unwrap_or(""), entity);
                    }
                    self.access.update_data_ptr(entity, &ty, null_mut());
                }
            },
        }
        *entity_override = EntityOverride::Deleted;
        Ok(())
    }
/// Destroy an entity and all its components
Destroy an entity and all its components
Destroy an entity and all its components
pub fn despawn(&self, entity: Entity) -> Result<(), NoSuchEntity> {
        if !self.access.is_entity_overridden(entity) {
            // if we don't have override data, create it before proceeding
            let override_data = EntityOverrideData::from_world(&self.world, entity)?;
            self.override_data
                .borrow_mut()
                .insert(entity, EntityOverride::Changed(override_data));
            self.access.set_entity_overridden(entity);
        }
        let mut override_map = self.override_data.borrow_mut();
        let entity_override = override_map
            .get_mut(&entity)
            .expect("override data not present despite entity being marked as overriden");
        match entity_override {
            EntityOverride::Deleted => return Err(NoSuchEntity),
            EntityOverride::Changed(data) => unsafe {
                for ty in &data.types {
                    if self.access.has_active_borrows(entity, ty.id()) {
                        panic!("Component {} on entity {:?} has an active borrow when despawning entity", ty.name().unwrap_or(""), entity);
                    }
                    self.access.update_data_ptr(entity, &ty, null_mut());
                }
            },
        }
        *entity_override = EntityOverride::Deleted;
        Ok(())
    }
pub fn despawn ( & self , entity : Entity ) -> Result < ( ) , NoSuchEntity > { if ! self . access . is_entity_overridden ( entity ) { // if we don't have override data, create it before proceeding let override_data = EntityOverrideData :: from_world ( & self . world , entity ) ? ; self . override_data . borrow_mut ( ) . insert ( entity , EntityOverride :: Changed ( override_data ) ) ; self . access . set_entity_overridden ( entity ) ; } let mut override_map = self . override_data . borrow_mut ( ) ; let entity_override = override_map . get_mut ( & entity ) . expect ( " " ) ; match entity_override { EntityOverride :: Deleted => return Err ( NoSuchEntity ) , EntityOverride :: Changed ( data ) => unsafe { for ty in & data . types { if self . access . has_active_borrows ( entity , ty . id ( ) ) { panic ! ( " " ty name ( ) unwrap_or ( " " ) entity ) ; } self . access . update_data_ptr ( entity , & ty , null_mut ( ) ) ; } } , } * entity_override = EntityOverride :: Deleted ; Ok ( ( ) ) }
Destroy an entity and all its components
Destroy an entity and all its components
&self
entity
Entity
&self
entity
Entity