Entity
Mojo struct 🡭
Entity
@register_passable_trivial
struct EntityEntity identifier. Holds an entity ID and it’s generation for recycling.
Entities are only created via the World, using World.add_entity.
⚠️ Important:
Entities are intended to be stored and passed around via copy, not via pointers!
The zero value should be used to indicate “nil”, and can be checked with Entity.is_zero.
Implemented traits
AnyType, Boolable, Copyable, Equatable, Hashable, ImplicitlyCopyable, ImplicitlyDeletable, Movable, RegisterPassable, TrivialRegisterPassable, Writable
Methods
Expand all Collapse all__init__
fn def __init__(accessor: EntityAccessor) -> Self
Initializes the entity from an
Args:EntityAccessor.
- accessor (
EntityAccessor): The entity accessor to initialize from.
Returns:
Self
__bool__
fn def __bool__(self) -> Bool
Returns whether this entity is not the zero entity.
Args:
- self (
Self)
Returns:
Bool
__eq__
fn def __eq__(self, other: Self) -> Bool
Compares two entities for equality.
Args:
- self (
Self) - other (
Self): The other entity to compare to.
Returns:
Bool
__ne__
fn def __ne__(self, other: Self) -> Bool
Compares two entities for inequality.
Args:
- self (
Self) - other (
Self): The other entity to compare to.
Returns:
Bool
__str__
fn def __str__(self) -> String
Returns a string representation of the entity.
Args:
- self (
Self)
Returns:
String
__hash__
fn def __hash__[H: Hasher](self, mut hasher: H)
Returns a unique hash of the entity.
Parameters:
- H (
Hasher)
Args:
- self (
Self) - hasher (
H)
get_id
fn def get_id(self) -> EntityId
Returns the entity’s ID.
Args:
- self (
Self)
Returns:
EntityId
get_generation
fn def get_generation(self) -> UInt32
Returns the entity’s generation.
Args:
- self (
Self)
Returns:
UInt32
is_zero
fn def is_zero(self) -> Bool
Returns whether this entity is the reserved zero entity.
Args:
- self (
Self)
Returns:
Bool