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()
public Entity()
Remarks
Entity generally shouldn't manually constructed
Properties
ArchetypicalComponentTypes
Gets the archetypical component types for this entity.
public readonly ImmutableArray<ComponentID> ArchetypicalComponentTypes { get; }
Property Value
Exceptions
- InvalidOperationException
Entity is dead.
ComponentTypes
Gets all the component types for this entity.
public readonly ImmutableArray<ComponentID> ComponentTypes { get; }
Property Value
Exceptions
- InvalidOperationException
Entity is dead.
IsAlive
Checks to see if this Entity is still alive
public readonly bool IsAlive { get; }
Property Value
IsNull
public readonly bool IsNull { get; }
Property Value
Null
The null entity
public static Entity Null { get; }
Property Value
OnComponentAddedGeneric
Raised when a component is added to an entity, with the generic parameter
public readonly GenericEvent? OnComponentAddedGeneric { get; set; }
Property Value
OnComponentRemovedGeneric
Raised when a component is removed to an entity, with the generic parameter
public readonly GenericEvent? OnComponentRemovedGeneric { get; set; }
Property Value
TagTypes
Gets tags the entity has
public readonly ImmutableArray<TagID> TagTypes { get; }
Property Value
Exceptions
- InvalidOperationException
Entity is dead.
Type
The EntityType of this Entity.
public readonly EntityType Type { get; }
Property Value
World
Gets the world this entity belongs to
public readonly World World { get; }
Property Value
Exceptions
- InvalidOperationException
Entity is dead.
Methods
AddAs(ComponentID, object)
Adds a component to this Entity, as a specific component type.
public readonly void AddAs(ComponentID componentID, object component)
Parameters
componentID
ComponentIDThe component type to add as.
component
objectThe component to add.
Exceptions
- InvalidCastException
component
is not assignable to the type represented bycomponentID
.
AddAs(Type, object)
Add a component to an Entity
public readonly void AddAs(Type type, object component)
Parameters
type
TypeThe type to add the component as. Note that a component of type DerivedClass and BaseClass are different component types.
component
objectThe component to add
AddBoxed(object)
Adds a component to this Entity as its own type
public readonly void AddBoxed(object component)
Parameters
component
objectThe component, which could be boxed
AddFromHandles(params ReadOnlySpan<ComponentHandle>)
Adds a set of components copied from component handles.
public readonly 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 readonly void Delete()
Detach(TagID)
Removes a tag from this Entity. Tags are like components but do not take up extra memory.
public readonly bool Detach(TagID tagID)
Parameters
tagID
TagIDThe type of tag to remove.
Returns
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 readonly bool Detach(Type type)
Parameters
type
TypeThe type of tag to remove.
Returns
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
EnumerateComponents(IGenericAction)
Enumerates all components one by one
public readonly void EnumerateComponents(IGenericAction onEach)
Parameters
onEach
IGenericActionThe unbound generic function called on each item
Equals(Entity)
public bool Equals(Entity other)
Parameters
other
EntityThe entity to compare with the current entity.
Returns
Equals(object?)
Determines whether the specified object is equal to the current Entity.
public override bool Equals(object? obj)
Parameters
obj
objectThe 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 readonly object Get(ComponentID id)
Parameters
id
ComponentIDThe 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 readonly object Get(Type type)
Parameters
type
TypeThe 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
.
GetEnumerator()
Gets a Entity.EntityComponentIDEnumerator that can be used to enumerate all component types on this entity.
public readonly Entity.EntityComponentIDEnumerator GetEnumerator()
Returns
Remarks
Can be used to enumerate sparse and archetypical component types without allocating.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
Get<T>()
Gets this Entity's component of type T
.
public readonly 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 readonly bool Has(ComponentID componentID)
Parameters
componentID
ComponentIDThe component ID of the component type to check.
Returns
Has(Type)
Checks to see if this Entity has a component of Type type
.
public readonly bool Has(Type type)
Parameters
type
TypeThe component type to check if this entity has.
Returns
Has<T>()
Checks to see if this Entity has a component of Type T
.
public readonly bool Has<T>()
Returns
Type Parameters
T
The type of component to check.
Remove(ComponentID)
Removes a component from this entity
public readonly void Remove(ComponentID componentID)
Parameters
componentID
ComponentIDThe ComponentID of the component to be removed
Remove(Type)
Removes a component from an Entity
public readonly void Remove(Type type)
Parameters
type
TypeThe 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 readonly void Set(ComponentID id, object obj)
Parameters
id
ComponentIDThe ID of the type of component to get
obj
objectThe 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 readonly void Set(Type type, object obj)
Parameters
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 readonly bool Tag(TagID tagID)
Parameters
tagID
TagIDThe tagID to use as the tag
Returns
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 readonly bool Tag(Type type)
Parameters
type
TypeThe type to use as a tag
Returns
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)
public readonly bool Tagged(TagID tagID)
Parameters
tagID
TagIDThe identifier of the tag to check.
Returns
Exceptions
- InvalidOperationException
Thrown if the Entity is not alive.
Tagged(Type)
public readonly bool Tagged(Type type)
Parameters
Returns
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 readonly bool Tagged<T>()
Returns
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 readonly bool TryGet(Type type, out object? value)
Parameters
type
TypeThe type of component to try and get
value
objectA wrapper over a reference to the component when true.
Returns
TryGet<T>(out Ref<T>)
Attempts to get a component from an Entity.
public readonly bool TryGet<T>(out Ref<T> value)
Parameters
Returns
Type Parameters
T
The type of component.
TryHas(ComponentID)
Checks of this Entity has a component specified by componentID
without throwing when dead.
public readonly bool TryHas(ComponentID componentID)
Parameters
componentID
ComponentIDThe component ID of the component type to check.
Returns
TryHas(Type)
Checks of this Entity has a component specified by type
without throwing when dead.
public readonly bool TryHas(Type type)
Parameters
type
TypeThe type of the component type to check.
Returns
TryHas<T>()
Checks of this Entity has a component specified by T
without throwing when dead.
public readonly bool TryHas<T>()
Returns
Type Parameters
T
The type of component to check.
Events
OnComponentAdded
Raised when a component is added to an entity
public readonly event Action<Entity, ComponentID> OnComponentAdded
Event Type
OnComponentRemoved
Raised when a component is removed from an entity
public readonly event Action<Entity, ComponentID> OnComponentRemoved
Event Type
OnDelete
Raised when the entity is deleted
public readonly event Action<Entity> OnDelete
Event Type
OnDetach
Raised when a tag is detached from the entity
public readonly event Action<Entity, TagID> OnDetach
Event Type
OnTagged
Raised when the entity is tagged
public readonly event Action<Entity, TagID> OnTagged
Event Type
Operators
operator ==(Entity, Entity)
Checks if two Entity structs refer to the same entity.
public static bool operator ==(Entity a, Entity b)
Parameters
Returns
operator !=(Entity, Entity)
Checks if two Entity structs do not refer to the same entity.
public static bool operator !=(Entity a, Entity b)