Search Unity

Get component array for a specific archetype

Discussion in 'Entity Component System' started by Deleted User, Aug 14, 2019.

  1. Deleted User

    Deleted User

    Guest

    GetComponentDataFromEntity
    returns a
    ComponentDataFromEntity
    . This data type contains component data for all entities.
    I was wondering if is it possible to only get component data of a speficic archetype?
    Is it is possible, does it make any difference in performance to only get component data for that specific archetype?

    Further explanation:
    I have many moving entities on screen. Bullets, Enemies, etc.
    I have different systems controlling positions of each archetype with IJobParallelFor job.
    I was wondering if it's possible to only give Bullets' Translate component to bullets job. This way these systems can work in parallel (Since they are not modifying the positions of same archetypes).
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    query.ToComponentDataArray<T>(Allocator) and query.CopyFromComponentDataArray for apply
    IJobForEach with required type and RequireComponentTag's or IJobForEach with EntityQuery overload on Schedule
     
  3. Deleted User

    Deleted User

    Guest

    Thank you. I didn't know that you can execute foreach job on query.
    So basically I can do this:
    Code (CSharp):
    1. shootingQuery = GetEntityQuery(ComponentType.ReadOnly<IsShooting>(), ComponentType.ReadOnly<Armed>());
    2. shootingQuery.SetFilter(new IsShooting(true));
    and schedule a shooting job like this:
    And it will only execute the ShootBulletsJob on the entities that have IsShooting = true.
    Is this correct?
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Yes, in that case IJFE will run on your query set of entities.
     
    Omniaffix-Dave likes this.