Skip to content

Game.Buildings.InstalledUpgrade

Assembly:
Assembly-CSharp (typical Cities: Skylines 2 runtime assembly; adjust if different)

Namespace:
Game.Buildings

Type:
struct InstalledUpgrade

Base:
Implements Unity.Entities.IBufferElementData, System.IEquatable, Colossal.Serialization.Entities.IEmptySerializable
Has attribute: [InternalBufferCapacity(0)]

Summary:
Represents a single installed upgrade entry for a building. This buffer element stores an Entity reference to the upgrade and a uint bitmask describing option flags for that installed upgrade. Intended to be used as an element type for DynamicBuffer attached to a building entity. Equality is based on the upgrade Entity only. The struct is serializable (IEmptySerializable) so it participates in the game's custom serialization pipeline.


Fields

  • public Entity m_Upgrade
    Holds the Entity that represents the installed upgrade prefab/component. May be Entity.Null when no valid upgrade is stored. This field is used for identity and lookup of the upgrade.

  • public uint m_OptionMask
    A bitmask of options or variants applied to this upgrade. The meaning of individual bits is defined by upgrade data elsewhere in the game/mod; typically used to encode toggles/choices for the installed upgrade.

Properties

  • None (no explicit C# properties are declared on this struct).
    The type exposes its data via public fields and an implicit conversion operator.

Constructors

  • public InstalledUpgrade(Entity upgrade, uint optionMask)
    Creates a new InstalledUpgrade with the given upgrade Entity and option mask.

Notes: - Being a value type (struct), it also has the default parameterless constructor that initializes fields to default (Entity.Null and 0).

Methods

  • public bool Equals(InstalledUpgrade other)
    Equality implementation from IEquatable<InstalledUpgrade>. Two InstalledUpgrade instances are considered equal if their m_Upgrade Entities are equal. The option mask is intentionally not considered for equality.

  • public override int GetHashCode()
    Returns the hash code of the m_Upgrade Entity. Keeps consistency with Equals (only upgrade influences hash).

  • public static implicit operator Entity(InstalledUpgrade upgrade)
    Implicit conversion operator allowing an InstalledUpgrade to be used where an Entity is expected: it returns upgrade.m_Upgrade. Useful for concise code when only the underlying Entity is needed.

Other notes: - The struct is decorated with [InternalBufferCapacity(0)], indicating zero internal preallocated capacity for the buffer element (size/performance implications when using DynamicBuffer).

Usage Example

// Example: add an installed upgrade to a building entity's buffer
Entity buildingEntity = ...;
Entity upgradeEntity = ...;
uint optionMask = 0x1; // example option flags

var buffer = entityManager.GetBuffer<Game.Buildings.InstalledUpgrade>(buildingEntity);
buffer.Add(new Game.Buildings.InstalledUpgrade(upgradeEntity, optionMask));

// Using the implicit conversion to get the Entity from an InstalledUpgrade element
Game.Buildings.InstalledUpgrade entry = buffer[0];
Entity storedUpgradeEntity = entry; // implicit operator returns entry.m_Upgrade

// Equality compares only the m_Upgrade entity
bool same = entry.Equals(new Game.Buildings.InstalledUpgrade(upgradeEntity, 0)); // true even if optionMask differs

{{ Additional information you may want for modding: - Use DynamicBuffer on building archetypes/components to store multiple installed upgrades per building. - If you rely on option mask semantics, define and document the bit assignments in your mod so other systems interpret the flags consistently. - Be cautious that Equals/GetHashCode ignore option mask; if you need distinct entries for same upgrade Entity with different masks, consider wrapping or changing equality semantics. - Because the struct implements IEmptySerializable, it will participate in the game's serialization; ensure compatibility when changing field layout. }}