Search Unity

Adding a populated DynamicBuffer to an entity inside of a job

Discussion in 'Entity Component System' started by Abbrew, Jul 12, 2019.

  1. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    I need to be able to both add a DynamicBuffer to an entity and then populate it with elements in the same job. This seems impossible at the moment because EntityCommandBuffer commands do not play back until after the job at the end of the frame, so the DynamicBuffer does not exist on the entity until then. Does anyone know any workarounds?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Code (CSharp):
    1. public DynamicBuffer<T> AddBuffer<T>(int jobIndex, Entity e) where T : struct, IBufferElementData
    EntityCommandBuffer returns the buffer straight away so you can manipulate it in the same job.
     
    Abbrew likes this.
  3. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Ahhh I should be looking more carefully. Thanks, this saved me from having to work out a convoluted hack