Struct ark_api::world::Entity

source ·
#[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§

source§

impl Entity

source

pub fn from_ffi(h: EntityHandle) -> Self

source

pub fn as_ffi(self) -> EntityHandle

source

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.

source

pub fn invalid() -> Self

Returns an eternally invalid entity handle.

source

pub fn try_from_ffi(h: EntityHandle) -> Option<Self>

source

pub fn try_to_ffi(self) -> Option<EntityHandle>

source§

impl Entity

Non-owning reference to an entity

source

pub fn create_empty(name: &str) -> Self

Creates an empty world entity with just a name.

Add components of your preference to it.

source

pub fn create(name: &str) -> Self

Creates a world entity with Transform, Render, Physics, and MeshStyle 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.

source

pub fn create_non_physics(name: &str) -> Self

Creates a world entity with Transform, Render and MeshStyle 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.

source

pub fn create_camera(name: &str) -> Self

Creates a world entity with a Camera and Transform component.

An entity with a Camera component is special in that the rotation of its transform component will be controlled directly by the client. See the documentation of Camera for more details.

source

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.

source

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

source

pub fn is_valid(self) -> bool

Lets you check whether this entity still exists and is valid.

source

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.

source

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.

source

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.

source

pub fn add_component(self, component_type: ComponentType)

Adds a component to an entity.

source

pub fn add<T: ComponentTrait>(self) -> T

Adds a component to an entity.

source

pub fn copy_component(self, src: Self, component_type: ComponentType)

Copies a component from the entity in src.

source

pub fn copy<T: ComponentTrait>(self, src: Self) -> T

Copies a component from the entity in src.

source

pub fn has<T: ComponentTrait>(self) -> bool

Returns whether the entity has the component or not.

source

pub fn get<T: ComponentTrait>(self) -> Option<T>

Gets an interface to the component.

Returns an option, none if the component doesn’t exist.

source

pub fn has_component(self, component_type: ComponentType) -> bool

Returns whether the entity has the component or not.

source

pub fn remove_component(self, component_type: ComponentType)

Removes a component from an entity.

source

pub fn remove<T: ComponentTrait>(self)

Removes a component from an entity.

source

pub fn name(self) -> String

Retrieves the name of the entity

source

pub fn entity_info(self) -> EntityInfo

Accessor for the EntityInfo component, if it exists.

source

pub fn mesh_style(self) -> MeshStyle

Accessor for the MeshStyle component, if it exists.

source

pub fn transform(self) -> Transform

Accessor for the Transform component, if it exists.

source

pub fn physics(self) -> Physics

Accessor for the Physics component, if it exists.

source

pub fn render(self) -> Render

Accessor for the Render component, if it exists.

source

pub fn d6_joint(self) -> D6Joint

Accessor for the D6Joint component, if it exists.

source

pub fn camera(self) -> Camera

Accessor for the Camera component, if it exists.

source

pub fn bounds(self) -> Bounds

Accessor for the Bounds component, if it exists.

source

pub fn tag(self) -> Tag

Accessor for the Tag component, if it exists.

source

pub fn layer(self) -> Layer

Accessor for the Layer component, if it exists.

source

pub fn sdf_model(self) -> SdfModel

Accessor for the SdfModel component, if it exists.

source

pub fn audio_source(self) -> AudioSource

Accessor for the AudioSource component, if it exists.

Trait Implementations§

source§

impl AsRef<Entity> for EntityOwned

source§

fn as_ref(&self) -> &Entity

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Entity

source§

fn clone(&self) -> Entity

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Entity

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&EntityOwned> for Entity

source§

fn from(item: &EntityOwned) -> Self

Converts to this type from the input type.
source§

impl Hash for Entity

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<Entity> for Entity

source§

fn eq(&self, other: &Entity) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a_, C_: Context> Readable<'a_, C_> for Entity

source§

fn read_from<R_: Reader<'a_, C_>>(_reader_: &mut R_) -> Result<Self, C_::Error>

source§

fn minimum_bytes_needed() -> usize

source§

fn read_from_buffer_with_ctx( context: C, buffer: &'a [u8] ) -> Result<Self, <C as Context>::Error>

source§

fn read_with_length_from_buffer_with_ctx( context: C, buffer: &'a [u8] ) -> (Result<Self, <C as Context>::Error>, usize)

source§

fn read_from_buffer_copying_data_with_ctx( context: C, buffer: &[u8] ) -> Result<Self, <C as Context>::Error>

source§

fn read_with_length_from_buffer_copying_data_with_ctx( context: C, buffer: &[u8] ) -> (Result<Self, <C as Context>::Error>, usize)

source§

fn read_with_length_from_buffer_copying_data_with_ctx_mut( context: &mut C, buffer: &[u8] ) -> (Result<Self, <C as Context>::Error>, usize)

source§

fn read_from_stream_unbuffered_with_ctx<S>( context: C, stream: S ) -> Result<Self, <C as Context>::Error>where S: Read,

source§

fn read_from_stream_buffered_with_ctx<S>( context: C, stream: S ) -> Result<Self, <C as Context>::Error>where S: Read,

source§

fn read_from_file_with_ctx( context: C, path: impl AsRef<Path> ) -> Result<Self, <C as Context>::Error>

source§

impl ValueConverterTrait<Entity> for ValueConverter

source§

fn into_value(v: Entity) -> Value

Wraps the passed-in value in a Value enum.
source§

fn from_value(v: &Value) -> Entity

Extracts the value from a Value enum.
source§

impl<C_: Context> Writable<C_> for Entity

source§

fn write_to<T_: ?Sized + Writer<C_>>( &self, _writer_: &mut T_ ) -> Result<(), C_::Error>

source§

fn write_to_buffer_with_ctx( &self, context: C, buffer: &mut [u8] ) -> Result<(), <C as Context>::Error>

source§

fn write_to_buffer_with_ctx_mut( &self, context: &mut C, buffer: &mut [u8] ) -> Result<(), <C as Context>::Error>

source§

fn write_to_vec_with_ctx( &self, context: C ) -> Result<Vec<u8, Global>, <C as Context>::Error>

source§

fn write_to_vec_with_ctx_mut( &self, context: &mut C ) -> Result<Vec<u8, Global>, <C as Context>::Error>

source§

fn write_to_stream_with_ctx<S>( &self, context: C, stream: S ) -> Result<(), <C as Context>::Error>where S: Write,

source§

fn write_to_file_with_ctx( &self, context: C, path: impl AsRef<Path> ) -> Result<(), <C as Context>::Error>

source§

fn bytes_needed(&self) -> Result<usize, <C as Context>::Error>

source§

impl Copy for Entity

source§

impl Eq for Entity

source§

impl StructuralEq for Entity

source§

impl StructuralPartialEq for Entity

source§

impl<T_> ZeroCopyable<T_> for Entitywhere EntityHandle: ZeroCopyable<T_>,

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.