Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

EntityCommandBuffer inside a Job

Discussion in 'Entity Component System' started by FabrizioSpadaro, Jun 15, 2019.

  1. FabrizioSpadaro

    FabrizioSpadaro

    Joined:
    Jul 10, 2012
    Posts:
    287
    Hello, I have a big problem, I always used EntityCommandBuffer inside a Jobs without any problem, using the same pattern every time, but for some reason, I can't manage to make it work now.

    Code (CSharp):
    1. public class OcclusionCullingSystem : JobComponentSystem {
    2.  
    3.   EntityCommandBufferSystem barrier;
    4.  
    5.   protected override void OnCreate() {
    6.     barrier = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
    7.   }
    8.   //[BurstCompile] one day they will have this thing working
    9.   struct OcclusionCullingJob : IJobForEachWithEntity<Bound2D> {
    10.     [ReadOnly] public float2 position;
    11.     [ReadOnly] public float2 scale;
    12.     [ReadOnly] public EntityCommandBuffer.Concurrent buffer;
    13.     public void Execute(Entity entity, int index, ref Bound2D Ebound) {
    14.       if(Bound2DExtension.Intersects(Ebound.position, Ebound.scale, position, scale)) {
    15.         if(!Ebound.visibile) {
    16.           buffer.AddComponent(index, entity, new RenderData { });
    17.           Ebound.visibile = true;
    18.         }
    19.       }
    20.       else if(Ebound.visibile) {
    21.         buffer.RemoveComponent<RenderData>(index, entity);
    22.         Ebound.visibile = false;
    23.       }
    24.     }
    25.   }
    26.  
    27.   protected override JobHandle OnUpdate(JobHandle inputDeps) {
    28.     float2[] datas = Bound2DExtension.OrthographicFromCamera(Camera.main);
    29.     var job = new OcclusionCullingJob() {
    30.       position = datas[0], scale = datas[1], buffer = barrier.CreateCommandBuffer().ToConcurrent()
    31.     }.Schedule(this, inputDeps);
    32.     barrier.AddJobHandleForProducer(inputDeps);
    33.     return job;
    34.   }
    35. }
    Any ideas ç_ç ?
     
  2. FabrizioSpadaro

    FabrizioSpadaro

    Joined:
    Jul 10, 2012
    Posts:
    287
    whoops, my bad..

    1. barrier.AddJobHandleForProducer(inputDeps);
    should be:

    1. barrier.AddJobHandleForProducer(job);
     
  3. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    What is the error you are receiving?

    EDIT: Oops too late :p
     
    FabrizioSpadaro likes this.