Struct bevy_internal::ecs::prelude::Entity [−][src]
pub struct Entity { /* fields omitted */ }
Expand description
Lightweight unique ID of an entity.
Obtained from World::spawn
, typically via
Commands::spawn
. Can be stored to refer to an entity in the
future.
Entity
can be a part of a query, e.g. Query<(Entity, &MyComponent)>
.
Components of a specific entity can be accessed using
Query::get
and related methods.
Implementations
Creates a new entity reference with the specified id
and a generation of 0.
Note
Spawning a specific entity
value is rarely the right choice. Most apps should favor
Commands::spawn
. This method should generally
only be used for sharing entities across apps, and only when they have a scheme
worked out to share an ID space (which doesn’t happen by default).
In general, one should not try to synchronize the ECS by attempting to ensure that
Entity
lines up between instances, but instead insert a secondary identifier as
a component.
There are still some use cases where it might be appropriate to use this function externally.
Examples
Initializing a collection (e.g. array
or Vec
) with a known size:
// Create a new array of size 10 and initialize it with (invalid) entities.
let mut entities: [Entity; 10] = [Entity::from_raw(0); 10];
// ... replace the entities with valid ones.
Deriving Reflect
for a component that has an Entity
field:
#[derive(Reflect, Component)]
#[reflect(Component)]
pub struct MyStruct {
pub entity: Entity,
}
impl FromWorld for MyStruct {
fn from_world(_world: &mut World) -> Self {
Self {
entity: Entity::from_raw(u32::MAX),
}
}
}
Convert to a form convenient for passing outside of rust.
Only useful for identifying entities within the same instance of an application. Do not use for serialization between runs.
No particular structure is guaranteed for the returned bits.
Reconstruct an Entity
previously destructured with Entity::to_bits
.
Only useful when applied to results from to_bits
in the same instance of an application.
Return a transiently unique identifier.
No two simultaneously-live entities share the same ID, but dead entities’ IDs may collide with both live and dead entities. Useful for compactly representing entities within a specific snapshot of the world, such as when serializing.
Returns the generation of this Entity’s id. The generation is incremented each time an entity with a given id is despawned. This serves as a “count” of the number of times a given id has been reused (id, generation) pairs uniquely identify a given Entity.
Trait Implementations
pub fn deserialize<D>(
deserializer: D
) -> Result<Entity, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
pub fn deserialize<D>(
deserializer: D
) -> Result<Entity, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Creates a clone of a reflected value, converting it to a concrete type if it was a dynamic types (e.g. DynamicStruct
)
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
pub fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
Returns a hash of the value (which includes the type) if hashing is supported. Otherwise
None
will be returned. Read more
Returns a “partial equal” comparison result if comparison is supported. Otherwise None
will be returned. Read more
Returns a serializable value, if serialization is supported. Otherwise None
will be
returned. Read more
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Entity
impl UnwindSafe for Entity
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
pub fn path(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
pub fn path_mut(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn get_path_mut<T>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>> where
T: Reflect,
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
pub fn vzip(self) -> V
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more