Hi all.
I’m currently having a problem with my DynamicBufferElements and maybe I misunderstood something there.
I’ve got a component data I want to store later in my dynamic buffer:
public struct TLTElementalFormData : IComponentData
{
public TLTElement ElementType;
public int CurrentDuration;
public Entity OwnEntity;
}
I create multiple entities for these and store them in a buffer:
var elementalFormEntity = entityManager.CreateEntity();
var elementalFormData = new TLTElementalFormData() { OwnEntity = elementalFormEntity, CurrentDuration = 3};
entityManager.AddComponentData(elementalFormEntity, elementalFormData);
elementBuffer.Add(new TLTElementalFormDataBufferElement(elementalFormData));
Works all fine and awesome. Now the problem:
The OwnEntity
entity I use later for setting the CurrentDuration
of that element:
var elementalFormData = entityManager.GetComponentData<TLTElementalFormData>(elementalFormEntity);
elementalFormData.CurrentDuration -= 1;
entityManager.SetComponentData(elementalFormData.OwnEntity, elementalFormData);
… which also works, but the element in the buffer is not changed.
From the entity debugger:
The entity (which is correctly changed. Note the “OwnerEntity” and “CurrentDuration”)
And the buffer entity (not changed. Same OwnerEntity):
So I guess my misconception is that the buffers elements can not be “referenced” via the entity, but rather I have to get the buffer itself and alter the elements in it?
Thanks for the help,
Patrick