Entity
The Entity, an abstract being, equipped with data.
In an entity component system (ECS), an entity is simply a unique ID tag. It represents an object in the game or application, but has no logic or data itself. The data and behavior come from components that are attached to this entity.
An Entity
is nothing more than a simple record struct Entity{ int ID, int WorldId, int Version }
. Either you work directly on this entity and its methods, or you simply use PURE_ECS
. More on this later.
Its components can be anything, primitive data types, structs and even classes! YOU determine which components and attributes an entity receives, there are no restrictions here!
Lifecycle
Creating entities is really simple!
Components may vary and this example uses generics, if you don't feel like using generics, there are still plenty of APIs without them.
How does it feel to be a god? Now lets step one further.
Change
Changing entities is of course also possible and also very easy.
The safety check using .Has<T>()
is important. Arch does not do this itself because because our mantra is raw performance and we trust you as a developer to know when to check and when not to.
We have now added a component to the entity (the pickaxe) and removed it again immediately. Now let's see how we can do this for several components at the same time.
Up to 25 generic overloads are available, order does not matter. This often saves code and is often faster.
Reference
We can easily reference other entities using the Entity
struct. Even if the entities recycle (and thus the Id of an entity can reappear), each Entity
has an Entity.Version
which functions as a timestamp.
We should always compare the Entity
s directly, never just via the Id!
So you can simply save an Entity
somewhere and use it as a direct reference to access it at any time.
Inspect
Inspecting entities is also a rather simple task.
The entity also has a debug view which reveals even more information.
Pitfalls
There are no hidden costs in Arch, everything happens directly without any black magic under the hood or hidden code slowing down your system. This means that everything is executed directly, without abstraction costs, the only disadvantage is that you have to make sure and check that your action makes sense at that point.
Even if it is possible to create entities during a query, change its structure or destroy it, we recommend buffering these operations and performing them after the query. Take a look at the examples!
Last updated
Was this helpful?