Entities & components
An entity is just an ID. What makes it interesting is the components attached to it.
Components and tags
Section titled “Components and tags”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 { }Creating entities
Section titled “Creating entities”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.
The EntityView shortcut
Section titled “The EntityView shortcut”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.
Destroying entities
Section titled “Destroying entities”goblin.DestroyEntity();world.ApplyCommands();Once you can create entities, the next step is asking which ones have what. See Queries.