Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Get component array for a specific archetype

Discussion in 'Data Oriented Technology Stack' 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,027
    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,027
    Yes, in that case IJFE will run on your query set of entities.
     
    Omniaffix-Dave likes this.
unityunity