Skip to content

Game.Citizens.HouseholdCitizen

Assembly: Game
Namespace: Game.Citizens

Type: struct

Base: IBufferElementData, IEquatable, IEmptySerializable

Summary:
Represents a reference to a citizen Entity stored as an element of an ECS dynamic buffer (household membership). Marked with [InternalBufferCapacity(5)] to give buffer instances a small preallocated capacity. This struct is a lightweight wrapper around an Entity (m_Citizen) and is intended for use with Unity's DOTS/ECS in Cities: Skylines 2 mod code and the game's Colossal serialization system (IEmptySerializable).


Fields

  • public Unity.Entities.Entity m_Citizen
    Holds the Entity representing the citizen. This is the value used for equality and hashing.

Properties

  • None (this type exposes the Entity directly via the m_Citizen field).

Constructors

  • public HouseholdCitizen(Unity.Entities.Entity citizen)
    Creates a new HouseholdCitizen wrapping the provided Entity.

Methods

  • public bool Equals(HouseholdCitizen other)
    Compares two HouseholdCitizen instances for equality by comparing their underlying Entity values (m_Citizen).

  • public override int GetHashCode()
    Returns the hash code of the underlying Entity (m_Citizen.GetHashCode()).

  • public static implicit operator Unity.Entities.Entity(HouseholdCitizen citizen)
    Implicitly converts a HouseholdCitizen to an Entity by returning the contained m_Citizen. Note: there is no implicit conversion from Entity to HouseholdCitizen; to create one from an Entity use the constructor.

Usage Example

// Example: adding citizens to a household buffer on an entity
var householdEntity = /* some Entity representing the household */;
var citizenEntity = /* some Entity representing a citizen */;

// Using an EntityCommandBuffer or EntityManager to get/create the buffer:
var buffer = entityManager.AddBuffer<Game.Citizens.HouseholdCitizen>(householdEntity);

// Add a citizen to the buffer
buffer.Add(new Game.Citizens.HouseholdCitizen(citizenEntity));

// You can also retrieve and compare elements:
for (int i = 0; i < buffer.Length; i++)
{
    var item = buffer[i];
    if (item.Equals(new Game.Citizens.HouseholdCitizen(citizenEntity)))
    {
        // found
    }
}

// Because of the implicit operator, a HouseholdCitizen can be used where an Entity is required:
Game.Citizens.HouseholdCitizen hc = new Game.Citizens.HouseholdCitizen(citizenEntity);
Unity.Entities.Entity e = hc; // implicit conversion to Entity

{{ Additional notes: - The [InternalBufferCapacity(5)] attribute sets the initial inlined capacity for the dynamic buffer to reduce allocations for small households. If you expect more members frequently, the buffer will grow beyond this. - Keep HouseholdCitizen as a lightweight container: store only the Entity reference. Avoid embedding large state in buffer elements. - Implements IEmptySerializable to participate in the game's Colossal.Serialization system for saving/loading where empty/default-serializable types are required. }}