Skip to content

Game.Prefabs.ObjectRequirementElement

Assembly: Assembly-CSharp (game code)
Namespace: Game.Prefabs

Type: struct

Base: Unity.Entities.IBufferElementData

Summary:
Represents a single requirement entry used by prefab/object requirement lists. Each element can either reference a specific Entity requirement (m_Requirement) or express requirements via flag masks (m_RequireFlags / m_ForbidFlags). Elements also include a group index (m_Group) and a requirement type (m_Type). The struct is an IBufferElementData and is marked with InternalBufferCapacity(0), meaning the default inline capacity is 0 and the buffer storage will be dynamic (heap) for entities that have this dynamic buffer.


Fields

  • public Entity m_Requirement
    Holds an entity reference that is required by this entry. When the requirement is expressed via flags instead, this field will typically be Entity.Null.

  • public ushort m_Group
    A group identifier (stored as a 16-bit unsigned integer). Groups can be used to categorize/partition multiple requirements (e.g., grouping alternatives or dependency sets).

  • public ObjectRequirementType m_Type
    Type of the requirement. This is an enum (defined elsewhere) describing the semantic kind of requirement this element represents. Defaults to enum value 0 when not explicitly provided.

  • public ObjectRequirementFlags m_RequireFlags
    Bitmask flags representing required attributes for this element. Used when the requirement is expressed as flags rather than an Entity reference.

  • public ObjectRequirementFlags m_ForbidFlags
    Bitmask flags representing attributes that are forbidden for this element. Used in combination with m_RequireFlags when the element is described via flags.

Properties

  • None.
    All data is exposed as public fields; there are no C# properties on this struct.

Constructors

  • public ObjectRequirementElement(Entity requirement, int group, ObjectRequirementType type = (ObjectRequirementType)0)
    Creates an element that references a specific Entity requirement. Sets m_Requirement to the provided Entity, m_Group to the provided group (cast to ushort), m_Type to the provided type, and initializes m_RequireFlags and m_ForbidFlags to zero.

  • public ObjectRequirementElement(ObjectRequirementFlags require, ObjectRequirementFlags forbid, int group, ObjectRequirementType type = (ObjectRequirementType)0)
    Creates an element that describes requirements via flag masks. Sets m_Requirement to Entity.Null, m_RequireFlags and m_ForbidFlags to the provided masks, m_Group to the provided group (cast to ushort), and m_Type to the provided type.

Methods

  • None.
    This struct contains only data and constructors; any logic operating on these elements is expected to live in systems that consume the DynamicBuffer.

Usage Example

// Example inside a system or initialization method that has access to an EntityManager / EntityCommandBuffer
// Assume 'entity' is an Entity that should hold the requirement buffer.

var buffer = entityManager.AddBuffer<ObjectRequirementElement>(entity);

// Add a requirement that points to a specific entity (e.g., a building prefab)
Entity requiredPrefab = /* obtain entity reference */;
int groupIndex = 0;
buffer.Add(new ObjectRequirementElement(requiredPrefab, groupIndex, ObjectRequirementType.Required));

// Add a requirement described by flags (require/forbid masks)
ObjectRequirementFlags requireMask = /* flags that must be present */;
ObjectRequirementFlags forbidMask = /* flags that must not be present */;
buffer.Add(new ObjectRequirementElement(requireMask, forbidMask, groupIndex, ObjectRequirementType.Optional));

Additional notes: - Because of InternalBufferCapacity(0), the buffer has no inline storage and will allocate storage on the heap; this is relevant for memory/GC considerations. - ObjectRequirementType and ObjectRequirementFlags are enums defined elsewhere in the codebase and determine the semantic meaning of the element's type and flag masks.