Questions about Buffer

Hi,

I’m new to unity ECS (and ECS in generale) and I have some questions.

As far I understand, to add an array of components to an entity I need to use Dynamic Buffers. By adding a buffer to an entity I can allocate space for components of type IBufferElementData. But how can I populate this buffer from within a system? The first solution that came to my mind is take the Buffer with EntityManager and then add elements to the buffer, but I don’t know if it’s the best solution.

PostUpdateCommands.AddBuffer<MovementElementBuffer>(data.Entity[i]);
                DynamicBuffer<MovementElementBuffer> movementBuffer = EntityManager.GetBuffer<MovementElementBuffer>(data.Entity[i]);
                movementBuffer.Add(new MovementElementBuffer { x = 0, y = 0 });
                movementBuffer.Add(new MovementElementBuffer { x = 1, y = 1 });

Another question, maybe more stupid: which is the best solution to check a global variable inside a system? Now I have a static monobehavior that acts as Singleton and store some boolean flags that I check within systems, but is the best things to do?

Thanks for the help!

Not void method and returns to you buffer, which you can modify.

Hi,
Please check this thread about buffer array.
It may give you some answers.