Search Unity

EntityCommandBuffer with jobs

Discussion in 'Entity Component System' started by rjohnson06, Nov 26, 2018.

  1. rjohnson06

    rjohnson06

    Joined:
    May 27, 2017
    Posts:
    17
    Can EntityCommandBuffer be used with any job type?

    Related to that, do you need to use EntityCommandBuffer.Concurrent with IJobProcessComponentData? If so, how do you know what to use for the JobIndex?

    I'm seeing some issues with command buffers and an IJobProcessComponentData job. I'm getting an "Invalid command buffer" error. I'm also seeing that the creation of the DamageArchetype entity is happening, but the SetComponentData command is not working, resulting in Damage entities with just default values.

    Code (CSharp):
    1. buffer.CreateEntity(Bootstrap.DamageArchetype);
    2.                         buffer.SetComponent<Damage>(new Damage() { Target = woodCutter.Tree, Amount = woodCutter.TreeDamage });
     
  2. dartriminis

    dartriminis

    Joined:
    Feb 3, 2017
    Posts:
    157
    IJobParallelFor, IJobChunk, and IJobProcessComponentData are parallel job types, therefore, you will need to use the concurrent version.

    For the job index, add
    [NativeSetThreadIndex] private int _threadIndex;
    to your job and use that.

    Also note that EntityCommandBuffer does not currently work with burst compiled jobs.
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    It works, but very limited yet. You can use ECB in bursted job for destroy entities.
     
    dartriminis, GilCat and rjohnson06 like this.
  4. rjohnson06

    rjohnson06

    Joined:
    May 27, 2017
    Posts:
    17
    Awesome, got it working, thanks.
     
  5. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Any idea when add/set component data with ECB in burst job? That would be great :)
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Not yet. ATM only destroy allowed.