Documentation

Unity Engine


Unity Engine


EntityQueryBuilder

Describes a query to find archetypes in terms of required, optional, and excluded components.
Read time 3 minutesLast updated 3 days ago

Definition

  • Type: Struct
  • Namespace: Unity.Entities
  • Assembly: UnityEngine.EntitiesModule
public ref struct EntityQueryBuilder

Remarks

EntityQueryBuilder is unmanaged and compatible with the Burst compiler. It is the recommended way to create an EntityQuery, and can be used for both SystemBase and ISystem.
Use an EntityQueryBuilder object to describe complex queries.
A query description combines the component types you specify (using methods like
WithAll
,
WithAny
, and
WithNone
) sets according to the following rules:
" All - Includes archetypes that have every component in this set, but only includes entities where the component is enabled. " Any - Includes archetypes that have at least one component in this set " None - Excludes archetypes that have any component in this set, but includes entities which have the component disabled. " Disabled - Includes archetypes that have every component in this set, but only matches entities where the component is disabled. " Absent - Excludes archetypes that have any component in this set. " Present - Includes archetypes that have every component in this set, whether or not the components are enabled.
For example, given entities with the following components:
" Player has components: ObjectPosition, ObjectRotation, Player " Enemy1 has components: ObjectPosition, ObjectRotation, Melee
  • Enemy2 has components: ObjectPosition, ObjectRotation, Ranger
The query description below matches all of the archetypes that: have any of [Melee or Ranger], AND have none of [Player], AND have all of [ObjectPosition and ObjectRotation]
In other words, the query created from this description selects the Enemy1 and Enemy2 entities, but not the Player entity.

Constructors

Constructor

Description

EntityQueryBuilder(Unity.Collections.AllocatorManager.AllocatorHandle)Create an entity query description builder.

Methods

Method

Description

AddAdditionalQueryAdd an additional query description to a single EntityQuery.
BuildCreate an EntityQuery owned by an EntityManager.
DisposeDispose the builder and release the memory.
ResetReset the builder for reuse.
WithAbsentAdd absent component types to the query.
WithAbsentChunkComponentAdd an absent Chunk Component type to the query.
WithAllAdd required component types to the query.
WithAllChunkComponentAdd a read-only required chunk component type to the query.
WithAllChunkComponentRWAdd a required chunk component type to the query.
WithAllRWAdd required component types to the query with ReadWrite mode.
WithAnyAdd optional component types to the query.
WithAnyChunkComponentAdd an optional read-only chunk component type to the query.
WithAnyChunkComponentRWAdd an optional chunk component type to the query.
WithAnyRWAdd optional component types to the query with ReadWrite mode.
WithDisabledAdd required disabled component types to the query.
WithDisabledRWAdd required disabled component types to the query with ReadWrite mode.
WithNoneAdd excluded component types to the query.
WithNoneChunkComponentAdd an excluded Chunk Component type to the query.
WithOptionsSet options for the current query.
WithPresentAdd required component types to the query, whether the type is enabled or not.
WithPresentChunkComponentAdd a required read-only chunk component type to the query, whether it is enabled or disabled.
WithPresentChunkComponentRWAdd a required chunk component type to the query, whether it is enabled or disabled.
WithPresentRWAdd required component types to the query with ReadWrite mode, whether they are enabled or disabled.