- Home /
when using Dynamic Buffers(ECS), How can you add two variables
Hello,I have been trying to write an inventory system with Dynamic Buffers with ECS. I want to know if it is more performant to have 150 items(all with an id) as the InternalBufferCapacity
or have 8 as the InternalBufferCapacity
with an id and an amount. 8 as the InternalBufferCapacity
would mean you need two integers in the buffer. Can You Even do that? Here is my Dynamic Buffer
[InternalBufferCapacity(150)]
[GenerateAuthoringComponent]
public struct InventoryBufferData : IBufferElementData
{
int id;
}
Answer by andrew-lukasik · Jul 24, 2021 at 02:22 PM
[InternalBufferCapacity(150)]
public struct InventoryBufferData : IBufferElementData
{
public int ID;
}
will allocate 600B / Entity:
{int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int}
[InternalBufferCapacity(8)]
public struct InventoryBufferData : IBufferElementData
{
public int ID;
public uint Amount;
}
will allocate 64B / Entity
{int,uint,int,uint,int,uint,int,uint,int,uint,int,uint,int,uint,int,uint}
Lower memory footprint won't correlate with increased performance necessarily, but it is a very reasonable default until more factors is known.
Answer by goldendonut · Jul 27, 2021 at 09:21 AM
well, what if I used an IcomponentData instead and had 4 slots with an id and an amount and did it that way instead.
[GenerateAuthoringComponent]
public struct InventoryData : IComponentData
{
public int Id1;
public int Amount1;
public int Id2;
public int Amount2;
public int Id3;
public int Amount3;
}
I don't think it's good to $$anonymous$$max this before gameplay requirements are more apparent. Consider this good-enough for now, keep it simple and move forward. Wait until you know how many items in what structure your game needs first - and optimize it then.
You can always re-arrange your data for performance later on. This is one of the advantages of Dots over OOP.