Skip to content

Entities

Jeremy Ries edited this page Jan 16, 2021 · 2 revisions

An entity is a collection of Components.

Source file of Entity:

  public class Entity : IEntity, IAERC
  { 
    ....
   private IComponent[] _components;
    ....
   }

In entitas the entities hold an array of IComponent's (for performance reasons).

Entities can be created and destroyed, destroying an entity also deletes all of it's components.

var e = _context.game.CreateEntity();
e.Destroy();

They "live" on a specific context -> see Contexts

[Game]
public sealed class PositionComponent : IComponent
{
    public IntVector2 Value;
}

void CreateDestroy(int x, int y)
{
    var entity = _context.game.CreateEntity();
    entity.AddPosition(new IntVector2(x, y));
    var pos = entity.position.Value;
    entity.RemovePosition();
}

Components can be added and removed, as long as the components context matches the entity's context.

To find a specific Entity a component with an EntityIndex can be used.

Further reading: EntitasCookbook/Entity

Clone this wiki locally