Best way to process an interaction of 2 archetypes in a Job?

Imagine you need to cross-reference all entities of type A with all entities of type B.

As I understand it, the way to do that is:

  • inside JobComponentSystem OnUpdate(), you get Components of A with GetEntityQuery(…).ToComponentDataArray(…).
  • assign this NativeArray(s) to field of job, that works with type B
  • do some logic inside that job accessing Components of archetypes of A and B

Is there a better way?

What you suggest is usually the best approach.

Chunk iteration is the other alternative and can make sense if avoiding the memcpy in ToComponentDataArray is optimal for your algorithm.

1 Like