I have two IBufferElementData of the same type on two different Entities. When I try to pass them to the same Job, Unity complains that they’re the same NativeArray.
var undoBuffer = EntityManager.GetBuffer<TreesBuffer>(_currentUndoEntity).Reinterpret<Entity>();
var changedTreesEvent = GetSingletonEntity<ChangedTreesEvent>();
var eventBuffer = EntityManager.GetBuffer<TreesBuffer>(changedTreesEvent).Reinterpret<Entity>();
result = new ApplyChangesJob
{
AllCheckedTrees = _treesToCheck,
TreesToDemolish = _treesToDemolish,
TreeIndicesToMarkChecked = _treeIndicesToMarkChecked,
Mountain = mountain,
EventEntity = changedTreesEvent,
EventBuffer = eventBuffer,
UndoBuffer = undoBuffer,
CommandBuffer = _ecbSystem.CreateCommandBuffer(),
}.Schedule(result);
InvalidOperationException: The writable NativeArray ApplyChangesJob.EventBuffer is the same NativeArray as ApplyChangesJob.UndoBuffer, two NativeArrays may not be the same (aliasing).
I’ve triple checked that _currentUndoEntity and changedTreesEvent are different Entities, and they both have a TreeBuffer on them. I’ve tried both having the buffer be part of the archetype when creating the Entities, as well as using AddBuffer after creating them. I’ve also tried not Reinterpreting one of the buffers in case that was causing the problem.
Is this a bug, or am I misunderstanding something about how buffers work under the hood? I’ve got other TreesBuffers elsewhere that work fine so this seems to be a problem specifically with passing two to the same job.