#[repr(transparent)]pub struct Entity(pub EntityHandle);
Expand description
An Entity is a single “thing” in the gameworld.
It can have multiple components attached, giving it a position in the world, a mesh to display, physical properties, and so forth.
The Entity struct has accessors to access its components, like transform
, mesh_style
,
physics
and so on.
Represents a raw non-owned reference to an entity, an EntityHandle
with functionality.
Use EntityOwned
if you want the entity to get destroyed if it goes out of scope.
Tuple Fields
0: EntityHandle
Implementations
sourceimpl Entity
impl Entity
pub fn from_ffi(h: EntityHandle) -> Self
pub fn as_ffi(self) -> EntityHandle
sourcepub fn is_valid_handle(self) -> bool
pub fn is_valid_handle(self) -> bool
Check if handle is valid
NOTE: This does not check whether there’s actually an entity represented by this
entity handle. For that, use World::is_valid_entity
.
pub fn try_from_ffi(h: EntityHandle) -> Option<Self>
pub fn try_to_ffi(self) -> Option<EntityHandle>
sourceimpl Entity
impl Entity
Non-owning reference to an entity
sourcepub fn create_empty(name: &str) -> Self
pub fn create_empty(name: &str) -> Self
Creates an empty world entity with just a name.
Add components of your preference to it.
sourcepub fn create_non_physics(name: &str) -> Self
pub fn create_non_physics(name: &str) -> Self
sourcepub fn create_camera(name: &str) -> Self
pub fn create_camera(name: &str) -> Self
sourcepub fn from_entity_owned(entity: &EntityOwned) -> Self
pub fn from_entity_owned(entity: &EntityOwned) -> Self
Creates a reference to an entity from an owned entity. This one won’t be owning the entity.
sourcepub fn try_into_entity_owned(self) -> Option<EntityOwned>
pub fn try_into_entity_owned(self) -> Option<EntityOwned>
If the entity exists in the global arena, you can use this to get ownership of this entity
sourcepub fn clone_entity(self, name: &str) -> Self
pub fn clone_entity(self, name: &str) -> Self
Clones this world entity and all its components.
name
- only used for display in the inspector and similar, it cannot later
be changed or queried to affect the game so don’t store data in it.
Will be concatenated to the name of the source of the clone.
Will always be cloned and placed in the global EntityArena
.
sourcepub fn try_destroy(self)
pub fn try_destroy(self)
Destroys the entity if it is in a global arena.
Further access to the entity (like by keeping the id around) after this is an error.
sourcepub fn schedule_for_destruction(self)
pub fn schedule_for_destruction(self)
Schedules the entity for destruction if it is in a global arena.
A call to EntityArena::global().destroy_pending_entities()
will
execute the order. Should usually be executed at the beginning of the
update function to destroy entities after an update step.
Further access to the entity (like by keeping the id around) after
EntityArena::global().destroy_pending_entities()
has been executed
is an error.
sourcepub fn add_component(self, component_type: ComponentType)
pub fn add_component(self, component_type: ComponentType)
Adds a component to an entity.
sourcepub fn add<T: ComponentTrait>(self) -> T
pub fn add<T: ComponentTrait>(self) -> T
Adds a component to an entity.
sourcepub fn copy_component(self, src: Self, component_type: ComponentType)
pub fn copy_component(self, src: Self, component_type: ComponentType)
Copies a component from the entity in src
.
sourcepub fn copy<T: ComponentTrait>(self, src: Self) -> T
pub fn copy<T: ComponentTrait>(self, src: Self) -> T
Copies a component from the entity in src
.
sourcepub fn has<T: ComponentTrait>(self) -> bool
pub fn has<T: ComponentTrait>(self) -> bool
Returns whether the entity has the component or not.
sourcepub fn get<T: ComponentTrait>(self) -> Option<T>
pub fn get<T: ComponentTrait>(self) -> Option<T>
Gets an interface to the component.
Returns an option, none if the component doesn’t exist.
sourcepub fn has_component(self, component_type: ComponentType) -> bool
pub fn has_component(self, component_type: ComponentType) -> bool
Returns whether the entity has the component or not.
sourcepub fn remove_component(self, component_type: ComponentType)
pub fn remove_component(self, component_type: ComponentType)
Removes a component from an entity.
sourcepub fn remove<T: ComponentTrait>(self)
pub fn remove<T: ComponentTrait>(self)
Removes a component from an entity.
sourcepub fn entity_info(self) -> EntityInfo
pub fn entity_info(self) -> EntityInfo
Accessor for the EntityInfo
component, if it exists.
sourcepub fn mesh_style(self) -> MeshStyle
pub fn mesh_style(self) -> MeshStyle
Accessor for the MeshStyle
component, if it exists.
sourcepub fn physics_character(self) -> PhysicsCharacter
pub fn physics_character(self) -> PhysicsCharacter
Accessor for the PhysicsCharacter
component, if it exists.
sourcepub fn audio_source(self) -> AudioSource
pub fn audio_source(self) -> AudioSource
Accessor for the AudioSource
component, if it exists.
Trait Implementations
sourceimpl AsRef<Entity> for EntityOwned
impl AsRef<Entity> for EntityOwned
sourceimpl From<&EntityOwned> for Entity
impl From<&EntityOwned> for Entity
sourcefn from(item: &EntityOwned) -> Self
fn from(item: &EntityOwned) -> Self
Converts to this type from the input type.
sourceimpl PartialEq<Entity> for Entity
impl PartialEq<Entity> for Entity
sourceimpl<'a_, C_: Context> Readable<'a_, C_> for Entity
impl<'a_, C_: Context> Readable<'a_, C_> for Entity
fn read_from<R_: Reader<'a_, C_>>(_reader_: &mut R_) -> Result<Self, C_::Error>
fn minimum_bytes_needed() -> usize
fn read_from_buffer_with_ctx(
context: C,
buffer: &'a [u8]
) -> Result<Self, <C as Context>::Error>
fn read_with_length_from_buffer_with_ctx(
context: C,
buffer: &'a [u8]
) -> (Result<Self, <C as Context>::Error>, usize)
fn read_from_buffer_copying_data_with_ctx(
context: C,
buffer: &[u8]
) -> Result<Self, <C as Context>::Error>
fn read_with_length_from_buffer_copying_data_with_ctx(
context: C,
buffer: &[u8]
) -> (Result<Self, <C as Context>::Error>, usize)
fn read_with_length_from_buffer_copying_data_with_ctx_mut(
context: &mut C,
buffer: &[u8]
) -> (Result<Self, <C as Context>::Error>, usize)
fn read_from_stream_unbuffered_with_ctx<S>(
context: C,
stream: S
) -> Result<Self, <C as Context>::Error> where
S: Read,
fn read_from_stream_buffered_with_ctx<S>(
context: C,
stream: S
) -> Result<Self, <C as Context>::Error> where
S: Read,
fn read_from_file_with_ctx(
context: C,
path: impl AsRef<Path>
) -> Result<Self, <C as Context>::Error>
sourceimpl ValueConverterTrait<Entity> for ValueConverter
impl ValueConverterTrait<Entity> for ValueConverter
sourcefn into_value(v: Entity) -> Value
fn into_value(v: Entity) -> Value
Wraps the passed-in value in a Value
enum.
sourcefn from_value(v: &Value) -> Entity
fn from_value(v: &Value) -> Entity
Extracts the value from a Value
enum.
sourceimpl<C_: Context> Writable<C_> for Entity
impl<C_: Context> Writable<C_> for Entity
fn write_to<T_: ?Sized + Writer<C_>>(
&self,
_writer_: &mut T_
) -> Result<(), C_::Error>
fn write_to_buffer_with_ctx(
&self,
context: C,
buffer: &mut [u8]
) -> Result<(), <C as Context>::Error>
fn write_to_buffer_with_ctx_mut(
&self,
context: &mut C,
buffer: &mut [u8]
) -> Result<(), <C as Context>::Error>
fn write_to_vec_with_ctx(
&self,
context: C
) -> Result<Vec<u8, Global>, <C as Context>::Error>
fn write_to_vec_with_ctx_mut(
&self,
context: &mut C
) -> Result<Vec<u8, Global>, <C as Context>::Error>
fn write_to_stream_with_ctx<S>(
&self,
context: C,
stream: S
) -> Result<(), <C as Context>::Error> where
S: Write,
fn write_to_file_with_ctx(
&self,
context: C,
path: impl AsRef<Path>
) -> Result<(), <C as Context>::Error>
fn bytes_needed(&self) -> Result<usize, <C as Context>::Error>
impl Copy for Entity
impl Eq for Entity
impl StructuralEq for Entity
impl StructuralPartialEq for Entity
impl<T_> ZeroCopyable<T_> for Entity where
EntityHandle: ZeroCopyable<T_>,
Auto Trait Implementations
impl RefUnwindSafe for Entity
impl Send for Entity
impl Sync for Entity
impl Unpin for Entity
impl UnwindSafe for Entity
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more