-
Notifications
You must be signed in to change notification settings - Fork 2
DelegateQuery
Martin Evans edited this page Jul 29, 2024
·
3 revisions
A delegate query is very similar to a query but it does not require defining a query type, instead it accepts a delegate.
_world.Query(static (ref Component1 c1, ref Component2 c2) => { /* whatever */ });
It is not required to mark the delegate static
, but it is highly recommended to avoid allocating closures! Sometimes it's useful pass in data which would normally be done with a closure, instead it can be explicitly passed:
_world.Query(some_data, static (SomeData some_data, ref Component1 c1, ref Component2 c2) => { /* whatever */ });
The first parameter to Query
(e.g. some_data
) is passed as the first parameter to the delegate. If you need to pass multiple things you can pass a tuple.
There is a parallel mode of delegate queries available, which will execute all entities in parallel.
void DoParallelQuery()
{
world.QueryParallel(static (ref Component1 c1, ref Component2 c2) => { /* whatever */ });
}