CachedEntityQuery Class
A cached query that maintains pre-resolved (Entity, Component) pairs for zero-overhead iteration. Automatically invalidates when entities gain or lose components. The cache rebuilds using pool-direct iteration, touching only entities with the queried components. Implements IDisposable; dispose when the owning system is removed mid-scene to stop receiving invalidation notifications and allow GC.
public class CachedEntityQuery<T1> : Brine2D.ECS.Query.CachedEntityQueryBase
where T1 : Brine2D.ECS.Component
Type parameters¶
T1
Inheritance System.Object → CachedEntityQueryBase → CachedEntityQuery\<T1>
| Methods | |
|---|---|
| Execute() | Executes the query and returns matching entities. The returned list is cached; no allocation occurs per call. |
| ForEach(Action<Entity,T1>) | Executes an action for each cached entity and its component. Components are pre-resolved; no pool lookup occurs in the hot path. Automatically parallelizes when entity count exceeds ECSOptions.ParallelEntityThreshold. |
| GetEnumerator() | Returns a struct enumerator over the cached (Entity, Component) pairs. Use with foreach for zero-allocation iteration; no delegate or closure is created. |