Table of Contents

Struct Entity

Namespace
Frent
Assembly
Frent.dll

An Entity reference; refers to a collection of components of unqiue types.

public struct Entity : IEquatable<Entity>
Implements
Inherited Members
Extension Methods

Constructors

Entity()

Creates an Entity identical to Null

public Entity()

Remarks

Entity generally shouldn't manually constructed

Properties

ComponentTypes

Gets the component types for this entity, ordered in update order

public ImmutableArray<ComponentID> ComponentTypes { get; }

Property Value

ImmutableArray<ComponentID>

Exceptions

InvalidOperationException

Entity is dead.

IsAlive

Checks to see if this Entity is still alive

public bool IsAlive { get; }

Property Value

bool

true if this entity is still alive (not deleted), otherwise false

IsNull

Checks to see if this Entity instance is the null entity: default(Entity)

public bool IsNull { get; }

Property Value

bool

Null

The null entity

public static Entity Null { get; }

Property Value

Entity

OnComponentAddedGeneric

Raised when a component is added to an entity, with the generic parameter

public GenericEvent? OnComponentAddedGeneric { get; readonly set; }

Property Value

GenericEvent

OnComponentRemovedGeneric

Raised when a component is removed to an entity, with the generic parameter

public GenericEvent? OnComponentRemovedGeneric { get; readonly set; }

Property Value

GenericEvent

TagTypes

Gets tags the entity has

public ImmutableArray<TagID> TagTypes { get; }

Property Value

ImmutableArray<TagID>

Exceptions

InvalidOperationException

Entity is dead.

Type

The EntityType of this Entity.

public EntityType Type { get; }

Property Value

EntityType

World

Gets the world this entity belongs to

public World World { get; }

Property Value

World

Exceptions

InvalidOperationException

Entity is dead.

Methods

AddAs(ComponentID, object)

Adds a component to this Entity, as a specific component type.

public void AddAs(ComponentID componentID, object component)

Parameters

componentID ComponentID

The component type to add as.

component object

The component to add.

Exceptions

InvalidCastException

component is not assignable to the type represented by componentID.

AddAs(Type, object)

Add a component to an Entity

public void AddAs(Type type, object component)

Parameters

type Type

The type to add the component as. Note that a component of type DerivedClass and BaseClass are different component types.

component object

The component to add

AddBoxed(object)

Adds a component to this Entity as its own type

public void AddBoxed(object component)

Parameters

component object

The component, which could be boxed

AddFromHandles(params ReadOnlySpan<ComponentHandle>)

Adds a set of components copied from component handles.

public void AddFromHandles(params ReadOnlySpan<ComponentHandle> componentHandles)

Parameters

componentHandles ReadOnlySpan<ComponentHandle>

The handles to copy components from.

Exceptions

ArgumentException

If adding componentHandles.Length.Length components will result in more than the maximum allowed commponent count.

Add<T>(in T)

Adds a component to this Entity.

public void Add<T>(in T c1)

Parameters

c1 T

Type Parameters

T

Remarks

If the world is being updated, changed are deffered to the end of the world update.

Delete()

Deletes this entity

public void Delete()

Detach(TagID)

Removes a tag from this Entity. Tags are like components but do not take up extra memory.

public bool Detach(TagID tagID)

Parameters

tagID TagID

The type of tag to remove.

Returns

bool

true if the Tag was removed successfully, false when the Entity doesn't have the component

Exceptions

InvalidOperationException

Entity is dead.

Detach(Type)

Removes a tag from this Entity. Tags are like components but do not take up extra memory.

public bool Detach(Type type)

Parameters

type Type

The type of tag to remove.

Returns

bool

true if the Tag was removed successfully, false when the Entity doesn't have the component

Exceptions

InvalidOperationException

Entity is dead.

Detach<T>()

Removes a tag from this Entity

public void Detach<T>()

Type Parameters

T

Remarks

If the world is being updated, changed are deffered to the end of the world update.

EntityTypeOf(ReadOnlySpan<ComponentID>, ReadOnlySpan<TagID>)

Gets an EntityType without needing an Entity of the specific type.

[Obsolete("Use ArchetypeID.EntityTypeOf instead")]
public static EntityType EntityTypeOf(ReadOnlySpan<ComponentID> components, ReadOnlySpan<TagID> tags)

Parameters

components ReadOnlySpan<ComponentID>

The components the EntityType should have.

tags ReadOnlySpan<TagID>

The tags the EntityType should have.

Returns

EntityType

EnumerateComponents(IGenericAction)

Enumerates all components one by one

public void EnumerateComponents(IGenericAction onEach)

Parameters

onEach IGenericAction

The unbound generic function called on each item

Equals(Entity)

Determines whether the specified Entity is equal to the current Entity.

public bool Equals(Entity other)

Parameters

other Entity

The entity to compare with the current entity.

Returns

bool

true if the specified entity is equal to the current entity; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to the current Entity.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current entity.

Returns

bool

true if the specified object is an Entity and is equal to the current entity; otherwise, false.

Get(ComponentID)

Gets this Entity's component of type id.

public object Get(ComponentID id)

Parameters

id ComponentID

The ID of the type of component to get

Returns

object

The boxed component.

Exceptions

InvalidOperationException

Entity is dead.

ComponentNotFoundException

Entity does not have component of type id.

Get(Type)

Gets this Entity's component of type type.

public object Get(Type type)

Parameters

type Type

The type of component to get

Returns

object

The component of type type

Exceptions

InvalidOperationException

Entity is dead.

ComponentNotFoundException

Entity does not have component of type type.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current Entity.

Get<T>()

Gets this Entity's component of type T.

public ref T Get<T>()

Returns

T

A reference to the component in memory.

Type Parameters

T

The type of component.

Exceptions

InvalidOperationException

Entity is dead.

NullReferenceException

Entity does not have component of type T.

Has(ComponentID)

Checks of this Entity has a component specified by componentID.

public bool Has(ComponentID componentID)

Parameters

componentID ComponentID

The component ID of the component type to check.

Returns

bool

true if the entity has a component of componentID, otherwise false.

Has(Type)

Checks to see if this Entity has a component of Type type.

public bool Has(Type type)

Parameters

type Type

The component type to check if this entity has.

Returns

bool

true if the entity has a component of type, otherwise false.

Has<T>()

Checks to see if this Entity has a component of Type T.

public bool Has<T>()

Returns

bool

true if the entity has a component of T, otherwise false.

Type Parameters

T

The type of component to check.

Remove(ComponentID)

Removes a component from this entity

public void Remove(ComponentID componentID)

Parameters

componentID ComponentID

The ComponentID of the component to be removed

Remove(Type)

Removes a component from an Entity

public void Remove(Type type)

Parameters

type Type

The type of component to remove

Exceptions

InvalidOperationException

Entity is dead.

ComponentNotFoundException

Entity does not have component of type type.

Remove<T>()

Removes a component from this Entity

public void Remove<T>()

Type Parameters

T

Remarks

If the world is being updated, changed are deffered to the end of the world update.

Set(ComponentID, object)

Gets this Entity's component of type id.

public void Set(ComponentID id, object obj)

Parameters

id ComponentID

The ID of the type of component to get

obj object

The component to set

Exceptions

InvalidOperationException

Entity is dead.

ComponentNotFoundException

Entity does not have component of type id.

Set(Type, object)

Gets this Entity's component of type type.

public void Set(Type type, object obj)

Parameters

type Type

The type of component to get

obj object

The component to set

Exceptions

InvalidOperationException

Entity is dead.

ComponentNotFoundException

Entity does not have component of type type.

Tag(TagID)

Adds a tag to this Entity. Tags are like components but do not take up extra memory.

public bool Tag(TagID tagID)

Parameters

tagID TagID

The tagID to use as the tag

Returns

bool

Remarks

Prefer the Tag(TagID) or Tag<T>() overloads. Use ID to get a TagID instance

Exceptions

InvalidOperationException

Entity is dead.

Tag(Type)

Adds a tag to this Entity. Tags are like components but do not take up extra memory.

public bool Tag(Type type)

Parameters

type Type

The type to use as a tag

Returns

bool

Exceptions

InvalidOperationException

Entity is dead.

Tag<T>()

Adds a tag to this Entity

public void Tag<T>()

Type Parameters

T

Remarks

If the world is being updated, changed are deffered to the end of the world update.

Tagged(TagID)

Checks whether this Entity has a specific tag, using a TagID to represent the tag.

public bool Tagged(TagID tagID)

Parameters

tagID TagID

The identifier of the tag to check.

Returns

bool

true if the tag identified by tagID has this Entity; otherwise, false.

Exceptions

InvalidOperationException

Thrown if the Entity is not alive.

Tagged(Type)

Checks whether this Entity has a specific tag, using a Type to represent the tag.

public bool Tagged(Type type)

Parameters

type Type

The Type representing the tag to check.

Returns

bool

true if the tag represented by type has this Entity; otherwise, false.

Remarks

Prefer the Tagged(TagID) or Tagged<T>() overloads. Use ID to get a TagID instance

Exceptions

InvalidOperationException

Thrown if the Entity not alive.

Tagged<T>()

Checks whether this Entity has a specific tag, using a generic type parameter to represent the tag.

public bool Tagged<T>()

Returns

bool

true if the tag of type T has this Entity; otherwise, false.

Type Parameters

T

The type used as the tag.

Exceptions

InvalidOperationException

Thrown if the Entity is not alive.

TryGet(Type, out object?)

Attempts to get a component from an Entity.

public bool TryGet(Type type, out object? value)

Parameters

type Type

The type of component to try and get

value object

A wrapper over a reference to the component when true.

Returns

bool

true if this entity has a component of type type, otherwise false.

TryGet<T>(out Ref<T>)

Attempts to get a component from an Entity.

public bool TryGet<T>(out Ref<T> value)

Parameters

value Ref<T>

A wrapper over a reference to the component when true.

Returns

bool

true if this entity has a component of type T, otherwise false.

Type Parameters

T

The type of component.

TryHas(ComponentID)

Checks of this Entity has a component specified by componentID without throwing when dead.

public bool TryHas(ComponentID componentID)

Parameters

componentID ComponentID

The component ID of the component type to check.

Returns

bool

true if the entity is alive and has a component of componentID, otherwise false.

TryHas(Type)

Checks of this Entity has a component specified by type without throwing when dead.

public bool TryHas(Type type)

Parameters

type Type

The type of the component type to check.

Returns

bool

true if the entity is alive and has a component of type, otherwise false.

TryHas<T>()

Checks of this Entity has a component specified by T without throwing when dead.

public bool TryHas<T>()

Returns

bool

true if the entity is alive and has a component of T, otherwise false.

Type Parameters

T

The type of component to check.

Events

OnComponentAdded

Raised when a component is added to an entity

public event Action<Entity, ComponentID> OnComponentAdded

Event Type

Action<Entity, ComponentID>

OnComponentRemoved

Raised when a component is removed from an entity

public event Action<Entity, ComponentID> OnComponentRemoved

Event Type

Action<Entity, ComponentID>

OnDelete

Raised when the entity is deleted

public event Action<Entity> OnDelete

Event Type

Action<Entity>

OnDetach

Raised when a tag is detached from the entity

public event Action<Entity, TagID> OnDetach

Event Type

Action<Entity, TagID>

OnTagged

Raised when the entity is tagged

public event Action<Entity, TagID> OnTagged

Event Type

Action<Entity, TagID>

Operators

operator ==(Entity, Entity)

Checks if two Entity structs refer to the same entity.

public static bool operator ==(Entity a, Entity b)

Parameters

a Entity

The first entity to compare.

b Entity

The second entity to compare.

Returns

bool

true if the entities refer to the same entity; otherwise, false.

operator !=(Entity, Entity)

Checks if two Entity structs do not refer to the same entity.

public static bool operator !=(Entity a, Entity b)

Parameters

a Entity

The first entity to compare.

b Entity

The second entity to compare.

Returns

bool

true if the entities do not refer to the same entity; otherwise, false.