Interface IBufferElementData
An interface for creating structs that can be stored in a DynamicBuffer<T>.
Namespace: Unity.Entities
Syntax
public interface IBufferElementData
Remarks
IBufferElementData implementations are subject to the same constraints as IComponentData.
Create a DynamicBuffer<T> containing a given type T
by adding that IBufferElementData type to
an entity. The DynamicBuffer container is created automatically. You can specify the maximum number of elements a buffer
stores inside a chunk by placing an InternalBufferCapacityAttribute on the IBufferElementData
declaration. When the number of elements exceeds the internal capacity, the entire is moved outside the chunk
into heap memory. (In either case, you access an element the same way through the dynamic buffer API.)
To remove a buffer from an entity, remove that entity's IBufferElementData component. (To remove an individual
element from a buffer, call
You can find entities with a particular type of buffer using either EntityQuery or EntityQueryBuilder in the same way you select entities with specific types of IComponentData. Use the IBufferElementData type in the query (not DynamicBuffer).
To access the buffer of an entity in a ComponentSystem, use GetBuffer<T>(Entity),
where T
is the IBufferElementData subtype.
To access the buffer of an entity in a ComponentSystemBase instance, define a field of type, GetBufferFromEntity<T>(Boolean), as part of the Job struct. Set the field value when you schedule the Job with Unity.Entities.EntityManager.GetBufferFromEntity``1(System.Boolean).
The DynamicBuffer interface provides array-like access to buffer contents. You can treat a buffer like a NativeArray. You can also use Reinterpret<U>() to treat the buffer as a container of the underlying type, rather than a container of IBufferElementData.
See Dynamic Buffers for additional information.