I have an entity that was created using EntityCommandBuffer then I want to set that entity to a variable in a buffer element. We can’t set the entity directly because it was created via EntityCommandBuffer. The entity must be set using also the EntityCommandBuffer but there’s no such method. I only see AppendToBuffer(). What I want is something like SetBufferElement(int sortKey, int index, T element).
// Say this is the buffer element
struct MyBufferElement : IBufferElement {
public Entity someOtherEntity;
... // Other variables
}
// Then somewhere along a job
public void Execute(...) {
...
Entity someNewEntity = this.commandBuffer.CreateEntity(...);
DynamicBuffer<MyBufferElement> elements = ...;
// We can't do this because someNewEntity is created via EntityCommandBuffer
// It's not an actual entity yet.
MyBufferElement element = elements[someIndex];
element.someOtherEntity = someNewEntity;
elements[someIndex] = element;
}
Also, I want to do this in a parallel writer.
The current solution I have in mind is to create another system that listens for newly created entities (using ISystemStateComponent) and then assign them to their owning entity.