Search Unity

Adding entity created with EntityCommandBuffer to DynamicBuffer element?

Discussion in 'Data Oriented Technology Stack' started by thelebaron, May 24, 2019.

  1. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    246
    I've got a bit of a conundrum: I'm creating an entity via a command buffer, and for the purposes of storing that entity's index/version in IComponentData (set by the same command buffer), it works.
    I'd like to store that entity in a IBufferElementData though, and as far as I can see, I cant use command buffers to do this, I can only store the immediate temporary entity id, rather than what will be created when the command buffer runs later. How should I be approaching this?
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    64
    The Unity DOTS team may have already fixed this issue. If not, then they are working on it.
     
  3. Creepgin

    Creepgin

    Joined:
    Dec 14, 2010
    Posts:
    232
    Are you saying the entity index returned by command buffer will no longer be temporary?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    4,615
    @thelebaron, I normally create entities on main thread for that purpose. You can use for example EntityManager, which returns created entities.
    Or
    you can generate entities with lets say SpareTag, using CommandBuffer, then run system / job which reads these spares and assign to desired buffer, and remove SpareTag.
     
  5. Brendon_Smuts

    Brendon_Smuts

    Joined:
    Jun 12, 2017
    Posts:
    43
    Does this post help you with your problem?
     
    Antypodish likes this.
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    4,615
    If OP is using Unity 2019+ should do :)
    That was missing in 2018.x, as far I am concerned.
     
  7. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    246
    @TRS6123 I believe I tested it with p33 this morning and I still got the negative integer result(not sure if this is intented behaviour or not, was this mentioned as a bug or something to be changed in the future?

    So I am using 2019.1 and for now I'm getting around it via the same method Antypodish suggested, just doing a deferred entity with the data that I want to be added to the buffer. That other approach is interesting I thought for a second it would work, but if the target buffer is just a singular entity and you have parallel job all copying the same buffer, I would assume it wouldn't have the desired outcome.

    Both seem more like stopgap solutions, whereas ideally I'd like a Add/RemoveBufferElement as an option for entity command buffers.
     
    Antypodish likes this.
  8. Brendon_Smuts

    Brendon_Smuts

    Joined:
    Jun 12, 2017
    Posts:
    43
    If you have a singular storage entity you can put the entity IDs from the instantiation job into a list and run a second job that adds the entire list to the DynamicBuffer in a single step. I’m not sure the command buffer approach is a stop gap, always felt to me like the intended usage. For sure there are some advantages to other methods but this is a pretty straight forward one.
     
    Last edited: May 25, 2019