Query
The Query, a way to select and iterate entities
Last updated
Was this helpful?
The Query, a way to select and iterate entities
Last updated
Was this helpful?
A Query
is a view of the and targets a specific set of . It only consists of a QueryDescription
, which specifies which entities with which structure are being searched for. You can specify which components an entity should definitely have, which it should perhaps have and which it should not have at all. It is also possible to search only for the exclusive structure of an entity. Let's take a look at this!
A normal iteration targets entities WITH specific components. In this example, we want to iterate over all entities that have Position
and Velocity
to move them.
It doesn't matter whether they are dwarves, elves or humans. As long as they have the Position & Velocity components, they move!
But what if we need more filters to have all entities except some specific ones? For example, everyone with a Pickaxe
EXCEPT Elves
to mine ores. It's time to make the queries a little more complex.
But there is another important filter. Imagine we are attacked and we now want to call all entities with a weapon to the defense. So we need everyone who has ANY weapon.
There is another case of filters. Sometimes we want to search for entities that have an exclusive set of components. No more and no less than that. In our example, a new type of dwarf that no longer wears pickaxes.
You want to give them an exclusive task. But how do we tell them apart from the rest? With one of those?
No. Both QueryDescriptions
would also target dwarfs that have additional components (e.g. [Dwarf, Position, Velocity, Bow
]). We do not want that.
Instead, we only want to target this one type of dwarf. No more or less components on them.
Next, perhaps we should take a look at what's under the hood of Arch.
You do not necessarily have to pass the in a Query
.