Skip to content

Game.Prefabs.BuildingUpgradeElement

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: System.ValueType, Unity.Entities.IBufferElementData, System.IEquatable

Summary:
Represents a single upgrade entry for a building prefab as an ECS dynamic buffer element. Each element holds an Entity reference (typically a prefab) that identifies the building upgrade. The struct is marked with [InternalBufferCapacity(0)], so no elements are stored inline on the entity (all are stored on the backing buffer storage).


Fields

  • public Unity.Entities.Entity m_Upgrade
    Holds an Entity reference to the upgrade (usually a prefab or prototype Entity representing the upgraded building). This is the value compared in equality and used to identify the upgrade target.

Properties

  • (none)

Constructors

  • public BuildingUpgradeElement(Unity.Entities.Entity upgrade)
    Initializes a new BuildingUpgradeElement with the provided Entity assigned to m_Upgrade.

Methods

  • public bool Equals(BuildingUpgradeElement other)
    Compares this element to another by comparing their m_Upgrade Entity values. Returns true when both reference the same Entity.

  • public override int GetHashCode()
    Returns the hash code of the contained Entity (m_Upgrade.GetHashCode()).

Usage Example

// Add and populate a dynamic buffer of BuildingUpgradeElement on an entity (e.g., a building prefab)
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

Entity buildingEntity = /* get or create building prefab entity */;
Entity upgradePrefabEntity = /* reference to the upgrade prefab entity */;

// Ensure the buffer exists and add an upgrade entry
var buffer = entityManager.GetBuffer<Game.Prefabs.BuildingUpgradeElement>(buildingEntity);
buffer.Add(new Game.Prefabs.BuildingUpgradeElement(upgradePrefabEntity));

// Alternatively, when creating the buffer for the first time:
var newBuffer = entityManager.AddBuffer<Game.Prefabs.BuildingUpgradeElement>(buildingEntity);
newBuffer.Add(new Game.Prefabs.BuildingUpgradeElement(upgradePrefabEntity));

{{ - Notes: This struct is designed for Unity DOTS / Entities usage. Since it implements IBufferElementData, use it via DynamicBuffer APIs. - Attribute: [InternalBufferCapacity(0)] forces the buffer to have zero inline capacity; all elements are stored externally (useful to save per-entity memory when many or variable upgrades exist). - Equality semantics: Equality is based solely on the referenced Entity. If Entities are compared across worlds or recreated, ensure Entity validity when using these values. }}