Skip to content

Game.Creatures.Resident

Assembly: Assembly-CSharp
Namespace: Game.Creatures

Type: struct (value type)

Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Resident is an ECS component that represents a "resident" (citizen) reference for an entity in the Cities: Skylines 2 mod codebase. It stores an Entity handle to the underlying citizen, a set of ResidentFlags describing state/behavior, and an integer timer used for transport/wait logic. The struct implements custom binary serialization through ISerializable and includes version-gated deserialization logic to maintain compatibility across save versions. Note that the citizen Entity reference (m_Citizen) is not written by the Serialize method in this struct and is handled elsewhere in the entity save/load pipeline.


Fields

  • public Entity m_Citizen
    Reference to the citizen entity associated with this resident component. This field is a raw Entities.Entity handle and is not serialized by this struct's Serialize method (entity references are generally managed separately by the entity serializer).

  • public ResidentFlags m_Flags
    Bitflags describing resident state (see ResidentFlags enum). Flags are serialized as a uint in Serialize/Deserialize. During deserialization older save versions may have certain flags cleared (see Deserialize notes).

  • public int m_Timer
    Integer timer used for transport/wait logic (e.g., waiting for transport). This field is only read/written when the save version supports it (see Deserialize).

Properties

  • This struct exposes no C# properties. All data is stored in public fields.

Constructors

  • public Resident()
    Implicit default constructor. All fields default to their zero values: m_Citizen = Entity.Null, m_Flags = 0, m_Timer = 0. There are no custom constructors defined in the type.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the ResidentFlags and m_Timer. Implementation details:
  • Writes m_Flags as a uint.
  • Writes m_Timer as an int.
  • Note: m_Citizen is not serialized here; entity references are typically serialized by the entity system.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the struct with version compatibility handling:

  • Reads a uint that is converted to ResidentFlags and stored in m_Flags.
  • If reader.context.version >= Version.transportWaitTimer, reads m_Timer from the stream.
  • After setting m_Flags from the read value, if reader.context.version < Version.yogaAreaFix, clears the IgnoreAreas flag from m_Flags to maintain correct behavior for older saves.
  • Important: m_Citizen is not read here and must be restored by the entity/archive system.

Usage Example

// Example: creating and attaching a Resident component to an entity
var resident = new Game.Creatures.Resident
{
    m_Citizen = citizenEntity,         // an Entity referencing a Citizen entity
    m_Flags = ResidentFlags.None,      // set flags as needed
    m_Timer = 0                        // initial timer value
};

entityManager.AddComponentData(targetEntity, resident);

// Serialization is handled by the system that invokes ISerializable implementations.
// The resident Serialize/Deserialize methods will be invoked by that system.