#EntityCommandBuffer Don't replace temporary references in IBufferElementData

1 messages · Page 1 of 1 (latest)

wicked leaf
#

As In the title. What cause that ? is this a bug with ECS ? Or something that is working as intended ?

I understand that ( from : https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/systems-entity-command-buffers.html)

The entities returned from EntityCommandBuffer's CreateEntity() and Instantiate() methods are special; they don't fully exist until the command buffer is played back

But at the end it's saying :

During command buffer playback, valid references to temporary entities created earlier in the buffer will be automatically replaced with a reference to the corresponding "real" entity.

So for me it sound like an issue.

raven musk
#

if you want references updated you need to use ecb to add the elements

#

var entity = ecb.CreateEntity();
ecb.AppendToBuffer(new Component {entity = entity});

#

for example

wicked leaf
#

LoWl Funny enought I just tried that before reading you message

#

and indeed that does work

#

Do you know of any way to modify an IBufferElementData directly with ecb ?

raven musk
#

you need to basically copy it

#
var newBuffer = ecb.SetBuffer<MyBuffer>(entity);
newBuffer.CopyFrom(existingBuffer);
newBuffer[12] = new MyBuffer {Entity = entity};```
#

this can break down though if you are editing this in multiple places

#

you really have to only make changes to this buffer in the 1 place

wicked leaf
#

& I supposed the logic is the same If I want to remove a bufferelement ?

#

@raven musk something like that :

  DynamicBuffer<ItemOnBelt> oldBuffer = _.SystemAPI.GetBuffer<ItemOnBelt>(Belt);
  DynamicBuffer<ItemOnBelt> newBuffer = ecb.SetBuffer<ItemOnBelt>(Belt);
  oldBuffer.RemoveAt(0);
  newBuffer.CopyFrom(oldBuffer);
#

cause you only have accesss to those 3 guys

#
foreach ((DynamicBuffer<ItemOnBelt> items)in SystemAPI.Query<DynamicBuffer<ItemOnBelt>>().WithEntityAccess())

Btw found out that this give me a read write access directy to the buffer 🙂

( can't use that for my question about removing an element )

raven musk
#

yeah you only need to use ecb to write deferred entities