Search Unity

  1. Curious about what's going to be in 2020.1? Have a look at the 2020.1 beta blog post.
    Dismiss Notice
  2. Want to see 2020.1b in action? Sign up for our Beta 2020.1 Overview Webinar on April 20th for a live presentation from our evangelists and a Q&A session with guests from R&D.
    Dismiss Notice
  3. Interested in giving us feedback? Join our online research interviews on a broad range of topics and share your insights with us.
    Dismiss Notice
  4. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Iterating on all entities in jobs that have a specific component w/o receiving an actual component

Discussion in 'Data Oriented Technology Stack' started by xVergilx, Jul 15, 2019.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,214
    There's IJobForEachWithEntity<T> that receives a component that is required to be iterated upon.
    Is there a way to iterate only entities without fetching an actual component to the job?

    E.g. which method would look like:
    Code (CSharp):
    1. public void Execute(Entity entity, int index) {
    2. }
    instead of
    Code (CSharp):
    1. private struct DisposeTempJob : IJobForEachWithEntity<T> {
    2.             public void Execute(Entity entity, int index, ref T c0) {  
    3.             }
    4. }
    I'm assuming that it has at least some overhead of sending refs vs sending only entity array.

    What I'm trying to achieve is to remove entities at the end of the simulation frame that are "marked" by the specific component.
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    135
    xVergilx likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,214
    Well, I've marked component right now as [ReadOnly].
    Probably IJobChunk is the best candidate for this kind of iteration. But IJobForEachWithEntity is too convienient to use in comparison to IJobChunk.
     
  4. digitaliliad

    digitaliliad

    Joined:
    Jul 1, 2018
    Posts:
    63
    The performant way to do that is to query for that specific component and then use a batch command like:
    Code (CSharp):
    1. EntityCommandBuffer.DestroyEntity(EntityQuery);
    2.  
     
    xVergilx and florianhanke like this.
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,214
    Oof. That's exactly what I've wanted. Thanks! :)
     
    digitaliliad likes this.
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,058
    S_Darkwell and xVergilx like this.
unityunity