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?
The Unity DOTS team may have already fixed this issue. If not, then they are working on it.
Are you saying the entity index returned by command buffer will no longer be temporary?
@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.
Does this post help you with your problem?
If OP is using Unity 2019+ should do ![]()
That was missing in 2018.x, as far I am concerned.
@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.
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.
Still interested in this.