Entity

Entity

Mojo struct 🡭

Entity

@register_passable_trivial
struct Entity

Entity 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, CollectionElement, Copyable, EqualityComparable, Hashable, Movable, Stringable, UnknownDestructibility

Methods

Expand all   Collapse all

__init__

fn __init__(accessor: EntityAccessor[archetype_mutability, archetype_origin, ComponentTypes, component_manager=component_manager]) -> Self

Initializes the entity from an EntityAccessor. Args:

  • accessor (EntityAccessor[archetype_mutability, archetype_origin, ComponentTypes, component_manager=component_manager]): The entity accessor to initialize from.

Returns:

Self

__bool__

fn __bool__(self) -> Bool

Returns whether this entity is not the zero entity. Args:

  • self (Self)

Returns:

Bool

__eq__

fn __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 __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 __str__(self) -> String

Returns a string representation of the entity. Args:

  • self (Self)

Returns:

String

__hash__

fn __hash__(self) -> UInt

Returns a unique hash of the entity. Args:

  • self (Self)

Returns:

UInt

get_id

fn get_id(self) -> SIMD[uint32, 1]

Returns the entity’s ID. Args:

  • self (Self)

Returns:

SIMD[uint32, 1]

get_generation

fn get_generation(self) -> SIMD[uint32, 1]

Returns the entity’s generation. Args:

  • self (Self)

Returns:

SIMD[uint32, 1]

is_zero

fn is_zero(self) -> Bool

Returns whether this entity is the reserved zero entity. Args:

  • self (Self)

Returns:

Bool