EntityQuery Class
Represents an executable entity query with filtering criteria.
public class EntityQuery
Inheritance System.Object → EntityQuery
| Methods | |
|---|---|
| Any() | Executes the query and checks if any entities match. |
| ApplyFilters(Entity) | Applies all query filters (component requirements, exclusions, behaviors, tags, enabled state, spatial, predicates). Active-status checks are handled per-overload for performance. |
| Clone() | Creates a copy of this query that can be further modified without affecting the original. All state is copied except random state, which is lazily initialized per clone. |
| Count() | Executes the query and returns the count of matching entities. |
| Execute() | Executes the query and returns matching entities. |
| ExecuteCore() | Dispatches to the pool-based path when the world is an EntityWorld and at least one .With<T>() filter is present; otherwise falls back to a full entity-list scan. |
| ExecuteCorePoolBased(EntityWorld) | Iterates the smallest required-component pool and checks remaining filters. Touches only entities that have at least one required component, not the full entity list. |
| First() | Executes the query and returns the first matching entity, or null. |
| ForEach(Action<Entity>) | Executes an action on each matching entity. |
| ForEach<T1,T2,T3,T4>(Action<Entity,T1,T2,T3,T4>) | Executes an action for each entity with 4 components. Iterates the smallest pool set; supports polymorphic queries. |
| ForEach<T1,T2,T3>(Action<Entity,T1,T2,T3>) | Executes an action for each entity with 3 components. Iterates the smallest pool set; supports polymorphic queries. |
| ForEach<T1,T2>(Action<Entity,T1,T2>) | Executes an action for each entity with 2 components. Iterates the smaller pool set for efficiency; supports polymorphic queries. |
| ForEach<T1>(Action<Entity,T1>) | Executes an action for each entity with 1 component. Iterates all assignable component pools; supports polymorphic queries. |
| ForEachOptimized(Func<Entity,bool>, Action<Entity>, bool) | Core optimized ForEach using ArrayPool for zero allocation. Used by the non-generic overload and the non-EntityWorld fallback path. |
| IncludeInactive() | Includes both active and inactive entities. |
| OnlyActive() | Includes only active entities (default behavior). |
| OnlyEnabled() | Filters to entities where all required components have IsEnabled set to true. Only the components specified via .With<T>() are checked. |
| OrderBy<TKey>(Func<Entity,TKey>) | Orders results by the specified selector in ascending order. |
| OrderByDescending<TKey>(Func<Entity,TKey>) | Orders results by the specified selector in descending order. |
| Random() | Executes the query and returns a single random matching entity, or null. |
| Random(int) | Executes the query and returns N random matching entities. |
| Skip(int) | Skips the first N entities from the results. |
| Take(int) | Takes only the first N entities from the results. |
| ThenBy<TKey>(Func<Entity,TKey>) | Applies a secondary sort criteria (tie-breaker). |
| ThenByDescending<TKey>(Func<Entity,TKey>) | Applies a secondary sort criteria in descending order. |
| TryGetPoolCount(int) | Fast path for Count()/Any(): returns the pool count directly when the query has a single required component, IncludeInactive() is set, and no other filters would reduce the result set. |
| Where(Func<Entity,bool>) | Adds a custom filter predicate. |
| With<T>(Func<T,bool>) | Requires entities to have the specified component. Optionally filters by component property values. |
| WithAllTags(string[]) | Requires entities to have ALL of the specified tags. |
| WithAnyTag(string[]) | Requires entities to have AT LEAST ONE of the specified tags. |
| WithBehavior<T>() | Requires entities to have the specified behavior. |
| WithinBounds(Rectangle) | Filters entities within a rectangular bounds. Requires entities to have a TransformComponent. Can be combined with WithinRadius(Vector2, float) for compound spatial filtering. |
| WithinRadius(Vector2, float) | Filters entities within a circular radius from a center point. Requires entities to have a TransformComponent. Can be combined with WithinBounds(Rectangle) for compound spatial filtering. |
| Without<T>() | Requires entities to NOT have the specified component. |
| WithoutBehavior<T>() | Requires entities to NOT have the specified behavior. |
| WithoutTag(string) | Requires entities to NOT have the specified tag. |
| WithTag(string) | Requires entities to have the specified tag. |