Skip to content
Jeff Campbell edited this page Aug 23, 2020 · 1 revision

An entity is a general purpose object with a unique identifier CreationIndex in a given Context. It is given a more-specific definition by a developer by adding, replacing, or removing one or more components to it. In this way, an entity on its own does not have any data associated with it other than it's CreationIndex ID and those components added to it. When an entity is created it has zero components and when destroyed all of it's components are removed. As with components, EntitasRedux pools entities for reuse.

When a developer creates components and then executes the Genesis code-generation process, additional APIs on the relevant entity to enable a developer to manipulate components on that type of entity.

Example Component Definitions

[Game]
public class PlayerComponent {}

[Game]
public class PositionComponent
{
    public Vector2Int value;
}

Example Entity API Usage

// Create an entity from the appropriate context. This enables usage of the code-generated 
// component APIs specific to that context.
var entity = Contexts.SharedInstance.Game.CreateEntity();

// Pseudo-component API usage
// Adding components
entity.IsPlayer = true;
entity.AddPosition(4,5);

// Replacing components
if(entity.HasPosition)
{
    var positionValue = entity.Position.value;
    positionValue += new Vector2Int(1,0);
    entity.ReplacePosition(positionValue);
}

// Removing components
entity.IsPlayer = false;
entity.RemovePosition();

// Destroying entity
entity.Destroy();