Search Unity

How to add to an existing DynamicBuffer through ECB?

Discussion in 'Entity Component System' started by jwvanderbeck, Jun 16, 2020.

  1. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Bit confused here. I have an entity with a DynamicBuffer on it. This buffer already contains some elements. The elements are entity references.

    I want to create new entities in a job, thus I am using an ECB, and then add those new entities to the existing buffer, appending to the end.

    However best I can tell, the ECB only lets me either add a new buffer to an entity that doesn't have one yet, or set a brand new empty buffer to one that does.

    What am I missing here?
     
  2. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    I don't think there is a way(this is something I would like to see personally). I got around it a while ago by using the ecb to create a new entity and component data with the values was adding to a buffer, and then having a separate job to process that entity and component data to add to the buffer.
     
  3. PeppeJ2

    PeppeJ2

    Joined:
    May 13, 2014
    Posts:
    43
    EntityCommandBuffer.AppendToBuffer
     
  4. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    I was amazed to find that this existed! And then sad to learn that EntityCommandBuffer.Concurrent doesn’t have an equivalent method. :(

    I haven’t yet dug much into the ECB source. Is there an obvious reason why something like this couldn’t have a Concurrent version?
     
  5. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    What do you mean? Seems to work for me.
     
    PublicEnumE likes this.
  6. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    oh excellent! I was looking at the wrong documentation. My mistake, and thank you.