Flecs: flecs::entity Struct Reference
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
flecs::entity Struct Reference
C++ API » Core » Entities

Entity. More...

`#include <entity.hpp>`

Inheritance diagram for flecs::entity:
[legend]

## Public Member Functions
| entity ()
| Default constructor.
| entity (const flecs::world_t *world, flecs::entity_t id)
| Wrap an existing entity ID.
| entity (world_t *world)
| Create a new entity.
| entity (world_t *world, const char *name, const char *sep="::", const char *root_sep="::")
| Create a named entity.
| entity (world_t *world, flecs::entity_t parent, const char *name, const char *sep="::", const char *root_sep="::")
| Create a named entity for a parent using ChildOf hierarchy storage.
| entity (world_t *world, const flecs::Parent &parent, const char *name=nullptr)
| Create a named entity for a parent using Parent hierarchy storage.
| entity (entity_t id)
| Conversion from flecs::entity_t to flecs::entity.
template<typename T>
T & | ensure () const
| Get mutable component value.
void * | ensure (entity_t comp) const
| Get mutable component value (untyped).
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
A & | ensure () const
| Get mutable reference for a pair.
template<typename First>
First & | ensure (entity_t second) const
| Get mutable reference for the first element of a pair.
void * | ensure (entity_t first, entity_t second) const
| Get mutable pointer for a pair (untyped).
template<typename Second>
Second & | ensure_second (entity_t first) const
| Get mutable reference for the second element of a pair.
template<typename T>
void | modified () const
| Signal that component was modified.
template<typename First, typename Second, typename A = actual_type_t<flecs::pair<First, Second>>>
void | modified () const
| Signal that the first element of a pair was modified.
template<typename First>
void | modified (entity_t second) const
| Signal that the first part of a pair was modified.
void | modified (entity_t first, entity_t second) const
| Signal that a pair has been modified (untyped).
void | modified (entity_t comp) const
| Signal that component was modified.
template<typename T, if_t< is_actual< T >::value > = 0>
ref< T > | get_ref_w_id (flecs::id_t component) const
| Get reference to component specified by component ID.
template<typename T, if_t< is_actual< T >::value > = 0>
ref< T > | get_ref () const
| Get reference to component.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
ref< A > | get_ref () const
| Get reference to component.
template<typename First, typename Second, typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>>
ref< A > | get_ref () const
| Get reference to pair component.
template<typename First>
ref< First > | get_ref (flecs::entity_t second) const
| Get reference to the first element of a pair.
untyped_ref | get_ref (flecs::id_t component) const
| Get untyped reference to component by component ID.
untyped_ref | get_ref (flecs::id_t first, flecs::id_t second) const
| Get untyped reference to pair by first and second entity IDs.
template<typename Second>
ref< Second > | get_ref_second (flecs::entity_t first) const
| Get reference to the second element of a pair.
void | clear () const
| Clear an entity.
void | destruct () const
| Delete an entity.
template<typename ... Args>
flecs::entity | child (flecs::entity_t r=flecs::ChildOf, Args &&... args)
| Create a child entity with a specified relationship.
template<typename R, typename ... Args>
flecs::entity | child (Args &&... args)
| Create a child entity with a typed relationship.
void | set_child_order (flecs::entity_t *children, int32_t child_count) const
| Set child order.
flecs::entity_view | view () const
| Return the entity as an entity_view.
const char * | from_json (const char *json)
| Deserialize an entity from JSON.
const char * | from_json (const char *json)
| Deserialize an entity from JSON.
Public Member Functions inherited from flecs::entity_builder< entity >
const entity & | set_doc_name (const char *name) const
| Set human-readable name.
const entity & | set_doc_brief (const char *brief) const
| Set brief description.
const entity & | set_doc_detail (const char *detail) const
| Set detailed description.
const entity & | set_doc_link (const char *link) const
| Set link to external documentation.
const entity & | set_doc_color (const char *color) const
| Set doc color.
const entity & | set_doc_uuid (const char *uuid) const
| Set doc UUID.
const entity & | observe (flecs::entity_t evt, Func &&callback) const
| Observe an event on an entity.
const entity & | observe (Func &&callback) const
| Observe an event on an entity.
const entity & | observe (Func &&callback) const
| Observe an event on an entity.
const entity & | set_json (flecs::id_t e, const char *json, flecs::from_json_desc_t *desc=nullptr) const
| Set a component from JSON.
const entity & | set_json (flecs::entity_t r, flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
| Set a pair from JSON.
const entity & | set_json (const char *json, flecs::from_json_desc_t *desc=nullptr) const
| Set a component from JSON.
const entity & | set_json (const char *json, flecs::from_json_desc_t *desc=nullptr) const
| Set a pair from JSON.
const entity & | set_json (flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
| Set a pair from JSON.
const entity & | set_json_second (flecs::entity_t r, const char *json, flecs::from_json_desc_t *desc=nullptr) const
| Set a pair from JSON.
| entity_view ()
| Default constructor.
| entity_view (flecs::world_t *world, flecs::id_t id)
| Wrap an existing entity ID.
| entity_view (entity_t id)
| Implicit conversion from flecs::entity_t to flecs::entity_view.
const entity & | add () const
| Add a component to an entity.
const entity & | add_second (flecs::entity_t first) const
| Add a pair.
const entity & | add_if (bool cond, flecs::id_t component) const
| Conditional add.
const entity & | is_a (entity_t second) const
| Shortcut for add(IsA, entity).
const entity & | child_of (entity_t second) const
| Shortcut for add(ChildOf, entity).
const entity & | depends_on (entity_t second) const
| Shortcut for add(DependsOn, entity).
const entity & | slot_of (entity_t second) const
| Shortcut for add(SlotOf, entity).
const entity & | slot () const
| Shortcut for add(SlotOf, target(ChildOf)).
const entity & | remove () const
| Remove a component from an entity.
const entity & | remove_second (flecs::entity_t first) const
| Remove a pair.
const entity & | auto_override (flecs::id_t id) const
| Mark ID for auto-overriding.
const entity & | auto_override_second (flecs::entity_t first) const
| Mark pair for auto-overriding.
const entity & | set_auto_override (const T &val) const
| Set component, mark component for auto-overriding.
const entity & | emplace_auto_override (Args &&... args) const
| Emplace component, mark component for auto-overriding.
const entity & | enable () const
| Enable an entity.
const entity & | disable () const
| Disable an entity.
const entity & | set_ptr (entity_t comp, size_t size, const void *ptr) const
const entity & | set (T &&value) const
| Set a component for an entity.
const entity & | set_second (entity_t first, const Second &value) const
| Set a pair for an entity.
const entity & | assign (T &&value) const
| Assign a component for an entity.
const entity & | assign_second (entity_t first, const Second &value) const
| Assign a pair for an entity.
const entity & | insert (const Func &func) const
| Set 1..N components.
const entity & | emplace (Args &&... args) const
| Emplace a component.
const entity & | emplace_first (flecs::entity_t second, Args &&... args) const
const entity & | emplace_second (flecs::entity_t first, Args &&... args) const
const entity & | with (const Func &func) const
| Entities created in the function will have the current entity.
const entity & | scope (const Func &func) const
| The function will be run with the scope set to the current entity.
const entity & | set_name (const char *name) const
| Set the entity name.
const entity & | set_alias (const char *name) const
| Set the entity alias.
const entity & | unit (const char *symbol, flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
| Make an entity a unit.
Public Member Functions inherited from flecs::entity_view
| entity_view ()
| Default constructor.
| entity_view (flecs::world_t *world, flecs::id_t id)
| Wrap an existing entity ID.
| entity_view (entity_t id)
| Implicit conversion from flecs::entity_t to flecs::entity_view.
entity_t | id () const
| Get entity ID.
bool | is_valid () const
| Check if entity is valid.
| operator bool () const
| Conversion to bool.
bool | is_alive () const
| Check if entity is alive.
flecs::string_view | name () const
| Return the entity name.
flecs::string_view | symbol () const
| Return the entity symbol.
flecs::string | path (const char *sep="::", const char *init_sep="::") const
| Return the entity path.
flecs::string | path_from (flecs::entity_t parent, const char *sep="::", const char *init_sep="::") const
| Return the entity path relative to a parent.
template<typename Parent>
flecs::string | path_from (const char *sep="::", const char *init_sep="::") const
| Return the entity path relative to a typed parent.
bool | enabled () const
| Check if entity is enabled (does not have the Disabled tag).
flecs::type | type () const
| Get the entity's type.
flecs::table | table () const
| Get the entity's table.
flecs::table_range | range () const
| Get table range for the entity.
template<typename Func>
void | each (const Func &func) const
| Iterate (component) IDs of an entity.
template<typename Func>
void | each (flecs::id_t first, flecs::id_t second, const Func &func) const
| Iterate matching pair IDs of an entity.
template<typename Func>
void | each (const flecs::entity_view &rel, const Func &func) const
| Iterate targets for a given relationship.
template<typename First, typename Func>
void | each (const Func &func) const
| Iterate targets for a given relationship.
template<typename Func>
void | children (flecs::entity_t rel, Func &&func) const
| Iterate children for an entity.
template<typename Rel, typename Func>
void | children (Func &&func) const
| Iterate children for an entity.
template<typename Func>
void | children (Func &&func) const
| Iterate children for an entity.
template<typename T, if_t< is_actual< T >::value > = 0>
const T * | try_get () const
| Get component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
const A * | try_get () const
| Get component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
const A * | try_get () const
| Get a pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
const First * | try_get (Second second) const
| Get a pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
const First * | try_get (Second constant) const
| Get a pair.
const void * | try_get (flecs::id_t comp) const
| Get component value (untyped).
const void * | try_get (flecs::entity_t first, flecs::entity_t second) const
| Get a pair (untyped).
template<typename... Ts>
auto | try_get_n () const
| Get multiple component values as a tuple of const pointers.
template<typename Second>
const Second * | try_get_second (flecs::entity_t first) const
| Get the second part for a pair.
template<typename First, typename Second>
const Second * | try_get_second () const
| Get the second part for a pair.
template<typename T, if_t< is_actual< T >::value > = 0>
const T & | get () const
| Get component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
const A & | get () const
| Get component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
const A & | get () const
| Get a pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
const First & | get (Second second) const
| Get a pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
const First & | get (Second constant) const
| Get a pair.
const void * | get (flecs::id_t comp) const
| Get component value (untyped).
const void * | get (flecs::entity_t first, flecs::entity_t second) const
| Get a pair (untyped).
template<typename Func, if_t< is_callable< Func >::value > = 0>
bool | get (const Func &func) const
| Get 1..N components.
template<typename... Ts>
auto | get_n () const
| Get multiple component values as a tuple of const references.
template<typename Second>
const Second & | get_second (flecs::entity_t first) const
| Get the second part for a pair.
template<typename First, typename Second>
const Second & | get_second () const
| Get the second part for a pair.
template<typename T, if_t< is_actual< T >::value > = 0>
T * | try_get_mut () const
| Get mutable component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
A * | try_get_mut () const
| Get mutable component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
A * | try_get_mut () const
| Get a mutable pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
First * | try_get_mut (Second second) const
| Get a mutable pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
First * | try_get_mut (Second constant) const
| Get a mutable pair.
void * | try_get_mut (flecs::id_t comp) const
| Get mutable component value (untyped).
void * | try_get_mut (flecs::entity_t first, flecs::entity_t second) const
| Get a mutable pair (untyped).
template<typename... Ts>
auto | try_get_mut_n () const
| Get multiple mutable component values as a tuple of pointers.
template<typename Second>
Second * | try_get_mut_second (flecs::entity_t first) const
| Get the second part for a pair.
template<typename First, typename Second>
Second * | try_get_mut_second () const
| Get the second part for a pair.
template<typename T, if_t< is_actual< T >::value > = 0>
T & | get_mut () const
| Get mutable component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
A & | get_mut () const
| Get mutable component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
A & | get_mut () const
| Get a mutable pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
First & | get_mut (Second second) const
| Get a mutable pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
First & | get_mut (Second constant) const
| Get a mutable pair.
void * | get_mut (flecs::id_t comp) const
| Get mutable component value (untyped).
void * | get_mut (flecs::entity_t first, flecs::entity_t second) const
| Get a mutable pair (untyped).
template<typename... Ts>
auto | get_mut_n () const
| Get multiple mutable component values as a tuple of references.
template<typename Second>
Second & | get_mut_second (flecs::entity_t first) const
| Get the second part for a pair.
template<typename First, typename Second>
Second & | get_mut_second () const
| Get the second part for a pair.
template<typename Enum>
Enum | get_constant () const
| Get enum constant for enum relationship.
template<typename First>
flecs::entity | target (int32_t index=0) const
| Get target for a given pair.
flecs::entity | target (flecs::entity_t first, int32_t index=0) const
| Get target for a given pair.
flecs::entity | target_for (flecs::entity_t relationship, flecs::id_t id) const
| Get the target of a pair for a given relationship ID.
template<typename T>
flecs::entity | target_for (flecs::entity_t relationship) const
| Get the target of a pair for a given relationship ID.
template<typename First, typename Second>
flecs::entity | target_for (flecs::entity_t relationship) const
| Get the target of a pair for a given relationship ID.
int32_t | depth (flecs::entity_t rel) const
| Get the depth for a given relationship.
template<typename Rel>
int32_t | depth () const
| Get the depth for a given relationship.
flecs::entity | parent () const
| Get parent of entity.
flecs::entity | lookup (const char *path, bool search_path=false) const
| Lookup an entity by name.
bool | has (flecs::id_t e) const
| Check if entity has the provided entity.
template<typename T>
bool | has () const
| Check if entity has the provided component.
template<typename E, if_t< is_enum< E >::value > = 0>
bool | has (E value) const
| Check if entity has the provided enum constant.
template<typename First, typename Second>
bool | has () const
| Check if entity has the provided pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
bool | has (Second second) const
| Check if entity has the provided pair.
template<typename Second>
bool | has_second (flecs::entity_t first) const
| Check if entity has the provided pair.
template<typename First, typename E, if_t< is_enum< E >::value &&!std::is_same< First, E >::value > = 0>
bool | has (E value) const
| Check if entity has the provided pair.
bool | has (flecs::id_t first, flecs::id_t second) const
| Check if entity has the provided pair.
bool | owns (flecs::id_t e) const
| Check if entity owns the provided entity.
template<typename First>
bool | owns (flecs::id_t second) const
| Check if entity owns the provided pair.
bool | owns (flecs::id_t first, flecs::id_t second) const
| Check if entity owns the provided pair.
template<typename T>
bool | owns () const
| Check if entity owns the provided component.
template<typename First, typename Second>
bool | owns () const
| Check if entity owns the provided pair.
template<typename Second>
bool | owns_second (flecs::entity_t first) const
| Check if entity owns the provided pair.
bool | enabled (flecs::id_t id) const
| Test if ID is enabled.
template<typename T>
bool | enabled () const
| Test if component is enabled.
bool | enabled (flecs::id_t first, flecs::id_t second) const
| Test if pair is enabled.
template<typename First>
bool | enabled (flecs::id_t second) const
| Test if pair is enabled.
template<typename First, typename Second>
bool | enabled () const
| Test if pair is enabled.
flecs::entity | clone (bool clone_value=true, flecs::entity_t dst_id=0) const
| Clone an entity.
flecs::entity | mut (const flecs::world &stage) const
| Return a mutable entity handle for the current stage.
flecs::entity | mut (const flecs::iter &it) const
| Same as mut(world), but for an iterator.
flecs::entity | mut (const flecs::entity_view &e) const
| Same as mut(world), but for an entity.
flecs::string | to_json (const flecs::entity_to_json_desc_t *desc=nullptr) const
| Serialize an entity to JSON.
const char * | doc_name () const
| Get human-readable name.
const char * | doc_brief () const
| Get brief description.
const char * | doc_detail () const
| Get detailed description.
const char * | doc_link () const
| Get link to external documentation.
const char * | doc_color () const
| Get color.
const char * | doc_uuid () const
| Get UUID.
int32_t | alert_count (flecs::entity_t alert=0) const
| Return the number of alerts for an entity.
template<typename E>
E | to_constant () const
| Convert an entity to an enum constant.
void | emit (flecs::entity_t evt) const
| Emit an event for an entity.
void | emit (flecs::entity evt) const
| Emit an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void | emit () const
| Emit an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void | emit (const Evt &payload) const
| Emit an event with payload for an entity.
void | enqueue (flecs::entity_t evt) const
| Enqueue an event for an entity.
void | enqueue (flecs::entity evt) const
| Enqueue an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void | enqueue () const
| Enqueue an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void | enqueue (const Evt &payload) const
| Enqueue an event with payload for an entity.
int32_t | alert_count (flecs::entity_t alert=0) const
| Return the number of alerts for an entity.
const char * | doc_name () const
| Get human-readable name.
const char * | doc_brief () const
| Get brief description.
const char * | doc_detail () const
| Get detailed description.
const char * | doc_link () const
| Get link to external documentation.
const char * | doc_color () const
| Get color.
const char * | doc_uuid () const
| Get UUID.
template<typename E>
E | to_constant () const
| Convert an entity to an enum constant.
void | emit (flecs::entity_t evt) const
| Emit an event for an entity.
void | emit (flecs::entity evt) const
| Emit an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void | emit () const
| Emit an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void | emit (const Evt &payload) const
| Emit an event with payload for an entity.
void | enqueue (flecs::entity_t evt) const
| Enqueue an event for an entity.
void | enqueue (flecs::entity evt) const
| Enqueue an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void | enqueue () const
| Enqueue an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void | enqueue (const Evt &payload) const
| Enqueue an event with payload for an entity.
flecs::string | to_json (const flecs::entity_to_json_desc_t *desc=nullptr) const
| Serialize an entity to JSON.
Public Member Functions inherited from flecs::id
| id (flecs::id_t value)
| id (flecs::world_t *world, flecs::id_t value=0)
| id (flecs::world_t *world, flecs::id_t first, flecs::id_t second)
| id (flecs::world_t *world, const char *expr)
| id (flecs::id_t first, flecs::id_t second)
| id (const flecs::id &first, const flecs::id &second)
bool | is_pair () const
| Test if ID is a pair (has first, second).
bool | is_wildcard () const
| Test if ID is a wildcard.
bool | is_entity () const
| Test if ID is an entity.
flecs::entity | entity () const
| Return ID as entity (only allowed when ID is a valid entity).
flecs::entity | add_flags (flecs::id_t flags) const
| Return ID with flags added.
flecs::entity | remove_flags (flecs::id_t flags) const
| Return ID with flags removed.
flecs::entity | remove_flags () const
| Return ID without flags.
flecs::entity | remove_generation () const
| Return ID without generation.
flecs::entity | type_id () const
| Return component type of ID.
bool | has_flags (flecs::id_t flags) const
| Test if ID has specified flags.
bool | has_flags () const
| Test if ID has any flags.
flecs::entity | flags () const
| Return ID flags set on ID.
bool | has_relation (flecs::id_t first) const
| Test if ID has the specified first element.
flecs::entity | first () const
| Get first element from a pair.
flecs::entity | second () const
| Get second element from a pair.
flecs::string | str () const
| Convert ID to string.
flecs::string | flags_str () const
| Convert flags of ID to string.
flecs::id_t | raw_id () const
| Return flecs::id_t value.
| operator flecs::id_t () const
flecs::world | world () const
| Get the world.

## Static Public Member Functions
static flecs::entity | null (const flecs::world_t *world)
| Entity ID 0.
static flecs::entity | null ()
| Entity ID 0 without a world.

## Additional Inherited Members
Protected Member Functions inherited from flecs::entity_builder< entity >
const entity & | to_base () const
Protected Attributes inherited from flecs::id
flecs::world_t * | world_
| World is optional, but guarantees that entity identifiers extracted from the ID are valid.
flecs::id_t | id_
| The raw ID value.
const entity & | unit (flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
| Make an entity a derived unit.
const entity & | unit_prefix (const char *symbol, int32_t factor=0, int32_t power=0) const
| Make an entity a unit prefix.
const entity & | quantity (flecs::entity_t quantity) const
| Add a quantity to a unit.
const entity & | quantity () const
| Add a quantity to a unit.
const entity & | quantity () const
| Make an entity a quantity.

## Detailed Description

Entity.

Class with read/write operations for entities.

Definition at line 29 of file entity.hpp.

## Constructor & Destructor Documentation

## ◆ entity() [1/7]

flecs::entity::entity | ( |  | ) |
| inline

Default constructor.

Creates an empty entity.

Definition at line 32 of file entity.hpp.

## ◆ entity() [2/7]

flecs::entity::entity | ( | const flecs::world_t * | world,
|  | flecs::entity_t | id )
| inlineexplicit

Wrap an existing entity ID.

Parameters

  world | The world in which the entity is created.
  id | The entity ID.

Definition at line 39 of file entity.hpp.

## ◆ entity() [3/7]

flecs::entity::entity | ( | world_t * | world | ) |
| inlineexplicit

Create a new entity.

Parameters

  world | The world in which to create the entity.

Definition at line 48 of file entity.hpp.

## ◆ entity() [4/7]

flecs::entity::entity | ( | world_t * | world,
|  | const char * | name,
|  | const char * | sep = "::",
|  | const char * | root_sep = "::" )
| inlineexplicit

Create a named entity.

Parameters

  world | The world in which to create the entity.
  name | The entity name.
  sep | String used to indicate scoping (Foo::Bar).
  root_sep | String used to indicate name is fully scoped (::Foo::Bar).

Definition at line 62 of file entity.hpp.

## ◆ entity() [5/7]

flecs::entity::entity | ( | world_t * | world,
|  | flecs::entity_t | parent,
|  | const char * | name,
|  | const char * | sep = "::",
|  | const char * | root_sep = "::" )
| inlineexplicit

Create a named entity for a parent using ChildOf hierarchy storage.

Parameters

  world | The world in which to create the entity.
  parent | The parent entity ID.
  name | The entity name.
  sep | String used to indicate scoping (Foo::Bar).
  root_sep | String used to indicate name is fully scoped (::Foo::Bar).

Definition at line 85 of file entity.hpp.

## ◆ entity() [6/7]

flecs::entity::entity | ( | world_t * | world,
|  | const flecs::Parent & | parent,
|  | const char * | name = nullptr )
| inlineexplicit

Create a named entity for a parent using Parent hierarchy storage.

The specified name cannot be a scoped identifier. For example:

- OK: "Foo"
- Not OK: "Foo::Bar"

Parameters

  world | The world in which to create the entity.
  parent | The parent entity.
  name | The entity name (optional).

Definition at line 111 of file entity.hpp.

## ◆ entity() [7/7]

flecs::entity::entity | ( | entity_t | id | ) |
| inlineexplicit

Conversion from flecs::entity_t to flecs::entity.

Parameters

  id | The entity_t value to convert.

Definition at line 124 of file entity.hpp.

## Member Function Documentation

## ◆ child() [1/2]

template<typename R, typename ... Args>

flecs::entity flecs::entity::child | ( | Args &&... | args | ) |
| inline

Create a child entity with a typed relationship.

Template Parameters

  R | The relationship type.

Parameters

  args | Additional arguments forwarded to entity creation.

Returns
  The created child entity.

Definition at line 439 of file entity.hpp.

## ◆ child() [2/2]

template<typename ... Args>

flecs::entity flecs::entity::child | ( | flecs::entity_t | r = flecs::ChildOf,
|  | Args &&... | args )
| inline

Create a child entity with a specified relationship.

Parameters

  r | The relationship to use (defaults to ChildOf).
  args | Additional arguments forwarded to entity creation.

Returns
  The created child entity.

Definition at line 427 of file entity.hpp.

## ◆ clear()

void flecs::entity::clear | ( |  | ) | const
| inline

Clear an entity.

This operation removes all components from an entity without recycling the entity ID.

See also
  ecs_clear()

Definition at line 406 of file entity.hpp.

## ◆ destruct()

void flecs::entity::destruct | ( |  | ) | const
| inline

Delete an entity.

Entities have to be deleted explicitly, and are not deleted when the entity object goes out of scope.

See also
  ecs_delete()

Definition at line 416 of file entity.hpp.

## ◆ ensure() [1/5]

template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>

A & flecs::entity::ensure | ( |  | ) | const
| inline

Get mutable reference for a pair.

This operation gets the value for a pair from the entity.

Template Parameters

  First | The first part of the pair.
  Second | The second part of the pair.

Returns
  Reference to the pair component value.

Definition at line 171 of file entity.hpp.

## ◆ ensure() [2/5]

template<typename T>

T & flecs::entity::ensure | ( |  | ) | const
| inline

Get mutable component value.

This operation returns a mutable reference to the component. If the entity did not yet have the component, it will be added. If a base entity had the component, it will be overridden, and the value of the base component will be copied to the entity before this function returns.

Template Parameters

  T | The component to get.

Returns
  Reference to the component value.

Definition at line 139 of file entity.hpp.

## ◆ ensure() [3/5]

void * flecs::entity::ensure | ( | entity_t | comp | ) | const
| inline

Get mutable component value (untyped).

This operation returns a mutable pointer to the component. If the entity did not yet have the component, it will be added. If a base entity had the component, it will be overridden, and the value of the base component will be copied to the entity before this function returns.

Parameters

  comp | The component to get.

Returns
  Pointer to the component value.

Definition at line 155 of file entity.hpp.

## ◆ ensure() [4/5]

void * flecs::entity::ensure | ( | entity_t | first,
|  | entity_t | second ) const
| inline

Get mutable pointer for a pair (untyped).

This operation gets the value for a pair from the entity. If neither the first nor second element of the pair is a component, the operation will fail.

Parameters

  first | The first element of the pair.
  second | The second element of the pair.

Returns
  Pointer to the pair component value.

Definition at line 202 of file entity.hpp.

## ◆ ensure() [5/5]

template<typename First>

First & flecs::entity::ensure | ( | entity_t | second | ) | const
| inline

Get mutable reference for the first element of a pair.

This operation gets the value for a pair from the entity.

Template Parameters

  First | The first part of the pair.

Parameters

  second | The second element of the pair.

Returns
  Reference to the first element value.

Definition at line 185 of file entity.hpp.

## ◆ ensure_second()

template<typename Second>

Second & flecs::entity::ensure_second | ( | entity_t | first | ) | const
| inline

Get mutable reference for the second element of a pair.

This operation gets the value for a pair from the entity.

Template Parameters

  Second | The second element of the pair.

Parameters

  first | The first element of the pair.

Returns
  Reference to the second element value.

Definition at line 214 of file entity.hpp.

## ◆ from_json()

const char * from_json | ( | const char * | json | ) |

Deserialize an entity from JSON.

Definition at line 11 of file entity.inl.

## ◆ get_ref() [1/6]

template<typename First, typename Second, typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>>

ref< A > flecs::entity::get_ref | ( |  | ) | const
| inline

Get reference to pair component.

Template Parameters

  First | The first element of the pair.
  Second | The second element of the pair.

Returns
  The reference.

Definition at line 348 of file entity.hpp.

## ◆ get_ref() [2/6]

template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>

ref< A > flecs::entity::get_ref | ( |  | ) | const
| inline

Get reference to component.

Overload for when T is not the same as the actual type, which happens when using pair types. A reference allows for quick and safe access to a component value, and is a faster alternative to repeatedly calling get() for the same component.

Template Parameters

  T | Component for which to get a reference.

Returns
  The reference.

Definition at line 333 of file entity.hpp.

## ◆ get_ref() [3/6]

template<typename T, if_t< is_actual< T >::value > = 0>

ref< T > flecs::entity::get_ref | ( |  | ) | const
| inline

Get reference to component.

A reference allows for quick and safe access to a component value, and is a faster alternative to repeatedly calling get() for the same component.

Template Parameters

  T | Component for which to get a reference.

Returns
  The reference.

Definition at line 319 of file entity.hpp.

## ◆ get_ref() [4/6]

template<typename First>

ref< First > flecs::entity::get_ref | ( | flecs::entity_t | second | ) | const
| inline

Get reference to the first element of a pair.

Template Parameters

  First | The first element of the pair.

Parameters

  second | The second element of the pair.

Returns
  The reference.

Definition at line 360 of file entity.hpp.

## ◆ get_ref() [5/6]

untyped_ref flecs::entity::get_ref | ( | flecs::id_t | component | ) | const
| inline

Get untyped reference to component by component ID.

Parameters

  component | The component ID.

Returns
  The untyped reference.

Definition at line 370 of file entity.hpp.

## ◆ get_ref() [6/6]

untyped_ref flecs::entity::get_ref | ( | flecs::id_t | first,
|  | flecs::id_t | second ) const
| inline

Get untyped reference to pair by first and second entity IDs.

Parameters

  first | The first element of the pair.
  second | The second element of the pair.

Returns
  The untyped reference.

Definition at line 380 of file entity.hpp.

## ◆ get_ref_second()

template<typename Second>

ref< Second > flecs::entity::get_ref_second | ( | flecs::entity_t | first | ) | const
| inline

Get reference to the second element of a pair.

Template Parameters

  Second | The second element of the pair.

Parameters

  first | The first element of the pair.

Returns
  The reference.

Definition at line 391 of file entity.hpp.

## ◆ get_ref_w_id()

template<typename T, if_t< is_actual< T >::value > = 0>

ref< T > flecs::entity::get_ref_w_id | ( | flecs::id_t | component | ) | const
| inline

Get reference to component specified by component ID.

A reference allows for quick and safe access to a component value, and is a faster alternative to repeatedly calling get() for the same component.

The method accepts a component ID argument, which can be used to create a ref to a component that is different from the provided type. This allows for creating a base type ref that points to a derived type:

flecs::ref<Base> r = e.get_ref_w_id<Base>(world.id<Derived>());
flecs::ref
Component reference.
Definition ref.hpp:108
flecs::world
The world.
Definition world.hpp:246
flecs::world::id
flecs::id id() const
Get ID from a type.
Definition impl.hpp:70

If the provided component ID is not binary compatible with the specified type, the behavior is undefined.

Template Parameters

  T | Component for which to get a reference.

Parameters

  component | The component ID to reference.

Returns
  The reference.

Definition at line 306 of file entity.hpp.

## ◆ modified() [1/5]

template<typename First, typename Second, typename A = actual_type_t<flecs::pair<First, Second>>>

void flecs::entity::modified | ( |  | ) | const
| inline

Signal that the first element of a pair was modified.

Template Parameters

  First | The first part of the pair.
  Second | The second part of the pair.

Definition at line 246 of file entity.hpp.

## ◆ modified() [2/5]

template<typename T>

void flecs::entity::modified | ( |  | ) | const
| inline

Signal that component was modified.

Template Parameters

  T | The component that was modified.

Definition at line 233 of file entity.hpp.

## ◆ modified() [3/5]

void flecs::entity::modified | ( | entity_t | comp | ) | const
| inline

Signal that component was modified.

Parameters

  comp | The component that was modified.

Definition at line 282 of file entity.hpp.

## ◆ modified() [4/5]

void flecs::entity::modified | ( | entity_t | first,
|  | entity_t | second ) const
| inline

Signal that a pair has been modified (untyped).

If neither the first nor the second element of the pair is a component, the operation will fail.

Parameters

  first | The first element of the pair.
  second | The second element of the pair.

Definition at line 274 of file entity.hpp.

## ◆ modified() [5/5]

template<typename First>

void flecs::entity::modified | ( | entity_t | second | ) | const
| inline

Signal that the first part of a pair was modified.

Template Parameters

  First | The first part of the pair.

Parameters

  second | The second element of the pair.

Definition at line 260 of file entity.hpp.

## ◆ null() [1/2]

flecs::entity flecs::entity::null | ( |  | ) |
| inlinestatic

Entity ID 0 without a world.

Returns
  An entity with ID 0 and no world.

Definition at line 491 of file entity.hpp.

## ◆ null() [2/2]

flecs::entity flecs::entity::null | ( | const flecs::world_t * | world | ) |
| inlinestatic

Entity ID 0.

This function is useful when the API must provide an entity that belongs to a world, but the entity ID is 0.

Parameters

  world | The world.

Returns
  An entity with ID 0.

Definition at line 480 of file entity.hpp.

## ◆ set_child_order()

void flecs::entity::set_child_order | ( | flecs::entity_t * | children,
|  | int32_t | child_count ) const
| inline

Set child order.

Changes the order of children as returned by entity::children(). Only applicable to entities with the flecs::OrderedChildren trait.

Parameters

  children | Array of child entity IDs in the desired order.
  child_count | Number of children in the array.

See also
  ecs_set_child_order()

Definition at line 453 of file entity.hpp.

## ◆ view()

flecs::entity_view flecs::entity::view | ( |  | ) | const
| inline

Return the entity as an entity_view.

This returns an entity_view instance for the entity, which is a read-only version of the entity class.

This is similar to a regular upcast, except that this method ensures that the entity_view instance is instantiated with a world vs. a stage, which a regular upcast does not guarantee.

Returns
  The entity_view.

Definition at line 467 of file entity.hpp.

The documentation for this struct was generated from the following files:

- include/flecs/addons/cpp/entity.hpp
- include/flecs/addons/cpp/mixins/json/entity.inl