Game.Tools.SelectionElement
Assembly:
Namespace: Game.Tools
Type: struct
Base: Unity.Entities.IBufferElementData
Summary:
Represents a single selection entry used in a DynamicBuffer on an entity. This struct is a simple buffer element that wraps a Unity.Entities.Entity reference. It is marked with [InternalBufferCapacity(0)], so the buffer has no inline storage capacity on the entity and will allocate externally (useful for minimizing entity memory footprint when the buffer is typically empty).
Fields
-
public Unity.Entities.Entity m_Entity
Holds the referenced entity that this selection element represents. This field is the payload of the buffer element and can be used to identify or operate on the selected entity. -
[InternalBufferCapacity(0)]
(type-level attribute)
Not a field but an attribute applied to the struct that sets the buffer's internal capacity to 0. This means no elements are stored directly in the entity; storage is allocated externally when elements are added.
Properties
- None.
Constructors
public SelectionElement(Unity.Entities.Entity entity)
Initializes a new SelectionElement with the given Entity value. Use this when adding elements to a DynamicBuffer.
Methods
- None.
Usage Example
// Add a SelectionElement buffer to an entity and push one element
var buffer = entityManager.AddBuffer<SelectionElement>(parentEntity);
buffer.Add(new SelectionElement(targetEntity));
// Read from a DynamicBuffer in a system or job
Entities
.WithAll<SomeSelectionOwnerTag>()
.ForEach((in Entity e, in DynamicBuffer<SelectionElement> selection) =>
{
for (int i = 0; i < selection.Length; i++)
{
Entity selected = selection[i].m_Entity;
// operate on selected...
}
}).Schedule();
Additional notes: - SelectionElement implements IBufferElementData and therefore must be a blittable value type. - Because the struct only stores an Entity, it is lightweight and suitable for use in ECS jobs and Burst-compiled code. - Use EntityCommandBuffer to add/remove buffer elements safely from structural change contexts (e.g., from jobs or outside main thread).