Skip to content

Entities & components

An entity is just an ID. What makes it interesting is the components attached to it.

A component is a struct implementing IComponent. It carries data, and it’s the unit archetype storage groups by.

public struct Health : IComponent { public int Current; public int Max; }

A tag is a struct implementing ITag instead. It carries no data, it just marks an entity as having some property.

public struct Stunned : ITag { }

All structural changes, creating entities, adding or removing components, go through a CommandBuffer. world.Commands is the world’s default one.

Entity goblin = world.Commands.CreateEntity()
.AddComponent(new Health { Current = 10, Max = 10 })
.AddTag<Stunned>();
world.ApplyCommands();

Nothing is queued into the world until world.ApplyCommands() runs. A query never sees a half-finished change mid-iteration.

CreateEntity() returns an EntityView, a chainable handle bound to one entity and the buffer it queues on. Once you have one, every mutation is a direct call on it:

goblin.RemoveTag<Stunned>()
.AddComponent(new Health { Current = 5, Max = 10 });
world.ApplyCommands();

See Systems for how a system’s Update gets one automatically.

goblin.DestroyEntity();
world.ApplyCommands();

Once you can create entities, the next step is asking which ones have what. See Queries.