pub struct Entity { /* private fields */ }Expand description
Associates a group of components within the world.
Entities are mostly just usize identifiers that help locate components,
but Entity comes with some conveniences.
After an entity is created you can attach and remove bundles of components asynchronously (or “lazily” if not in an async context).
let mut world = World::default();
// asynchronously create new entities from within an async system
world.with_async_system("spawn-b-entity", |mut facade: Facade| async move {
let mut b = facade
.visit(|mut ents: Write<Entities>| {
Ok(ents.create().with_bundle((123, "entity B", true)))
})
.await?;
// after this await `b` has its bundle
b.updates().await;
// visit a component or bundle
let did_visit = b
.visit::<&&str, ()>(|name| assert_eq!("entity B", *name.value()))
.await
.is_some();
Ok(())
});
world.run();Alternatively, if you have access to the Components resource you can
attach components directly and immediately.
Implementations
sourceimpl Entity
impl Entity
pub fn id(&self) -> usize
sourcepub fn with_bundle<B: IsBundle + Send + Sync + 'static>(self, bundle: B) -> Self
pub fn with_bundle<B: IsBundle + Send + Sync + 'static>(self, bundle: B) -> Self
Lazily add a component bundle to archetype storage.
This entity will have the associated components after the next tick.
sourcepub fn insert_bundle<B: IsBundle + Send + Sync + 'static>(&mut self, bundle: B)
pub fn insert_bundle<B: IsBundle + Send + Sync + 'static>(&mut self, bundle: B)
Lazily add a component bundle to archetype storage.
This entity will have the associated components after the next tick.
sourcepub fn insert_component<T: Send + Sync + 'static>(&mut self, component: T)
pub fn insert_component<T: Send + Sync + 'static>(&mut self, component: T)
Lazily add a component bundle to archetype storage.
This entity will have the associated component after the next tick.
sourcepub fn remove_component<T: Send + Sync + 'static>(&mut self)
pub fn remove_component<T: Send + Sync + 'static>(&mut self)
Lazily remove a component bundle to archetype storage.
This entity will have lost the associated component after the next tick.
Methods from Deref<Target = usize>
Trait Implementations
sourceimpl Clone for Entity
impl Clone for Entity
You may clone entities, but each one does its own lazy updates, separate from all other clones.