Skip to content

Game.Buildings.CitizenPresence

Assembly: Assembly-CSharp
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Component used by the game's ECS to represent the presence of citizens at/around a building. It stores a small signed delta (change in presence) and a byte representing the current presence value. Implements Colossal's ISerializable interface so it can be written to and restored from the game's serialization streams, and implements IQueryTypeParameter so it can be used in entity queries.


Fields

  • public sbyte m_Delta Stores the signed change in presence since the last update. Range is that of sbyte (-128..127). Typically used to accumulate small increments/decrements to the presence count when citizens enter/leave or when presence is adjusted by simulation logic.

  • public byte m_Presence Current presence value for the building (0..255). Represents the measured/recorded count or a compacted presence metric for the building. Stored as a byte to keep the component compact for large ECS archetypes.

Properties

  • This struct exposes no properties. The data is stored in public fields and accessed directly.

Constructors

  • public CitizenPresence()
    No user-defined constructors are present; the struct has the implicit parameterless constructor. Instantiate using object initializer syntax when adding to entities, e.g. new CitizenPresence { m_Delta = 1, m_Presence = 10 }.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component's fields to the provided writer in the order: m_Delta then m_Presence. This ensures the component can be persisted by the game's serialization system.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component's fields from the provided reader into m_Delta and m_Presence (same order used by Serialize). Uses reference reads so the underlying fields get assigned directly.

Usage Example

// Create and assign the component to an entity via EntityManager
var presence = new CitizenPresence {
    m_Delta = 1,
    m_Presence = 5
};
entityManager.AddComponentData(entity, presence);

// Example: modify fields directly
var current = entityManager.GetComponentData<CitizenPresence>(entity);
current.m_Delta += -1;
current.m_Presence = (byte)Mathf.Max(0, current.m_Presence - 1);
entityManager.SetComponentData(entity, current);

// Serialization is handled by the game via ISerializable; custom writers/readers would call:
// presence.Serialize(writer);
// presence.Deserialize(reader);