Search Unity

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

Discussion in 'Entity Component System' started by saint_angels, Aug 5, 2019.

  1. saint_angels

    saint_angels

    Joined:
    Aug 4, 2019
    Posts:
    1
    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?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    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.
     
    saint_angels likes this.