Skip to content

Game.Citizens.TouristHousehold

Assembly: Assembly-CSharp
Namespace: Game.Citizens

Type: struct

Base: implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
Represents a tourist household component used by the ECS to track a tourist group's association with a hotel and when they will leave. This struct is a plain data component (IComponentData) and supports serialization via the ISerializable interface used by the Colossal framework. It is intended for use in systems that manage tourist behaviour, hotel occupancy and leaving/scheduling logic in Cities: Skylines 2 modding.


Fields

  • public Unity.Entities.Entity m_Hotel
    The Entity reference to the hotel the tourist household is staying at. This is stored as an Entity handle so systems can resolve or query hotel data/components. When deserializing, this will be read back into the component.

  • public uint m_LeavingTime
    The time (simulation tick or game time unit) when the tourist household is scheduled to leave the hotel or city. The unit (seconds, ticks, game ticks) depends on the surrounding simulation code — inspect related systems for the exact timebase used.

Properties

  • None. This struct exposes plain public fields and does not define C# properties.

Constructors

  • Implicit default constructor public TouristHousehold()
    As a struct there is an implicit default constructor that initializes fields to default values (m_Hotel = default Entity, m_LeavingTime = 0). Populate fields explicitly when adding the component to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the component fields in order: first writes the hotel Entity, then the leaving time (uint). Used by the game's serialization pipeline to persist component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes component fields in the same order as Serialize: reads an Entity into m_Hotel and then reads a uint into m_LeavingTime. Uses ref locals to write directly into the struct fields.

Notes on serialization: - The implementation writes and reads the raw Entity value and the uint leaving time. When implementing save/load or network replication, ensure any entity remapping (if used) is accounted for by the surrounding serialization framework. - Keep the read/write order consistent between Serialize and Deserialize to avoid corrupting component state.

Usage Example

// Creating and assigning the component to an entity (EntityManager API example)
var tourist = new Game.Citizens.TouristHousehold
{
    m_Hotel = hotelEntity,          // an existing hotel Entity
    m_LeavingTime = currentTime + 600u // e.g., leave after 600 simulation ticks
};
entityManager.SetComponentData(touristEntity, tourist);

// Example pseudo-serialization usage (writer/reader are provided by engine serialization pipeline)
tourist.Serialize(writer);
// ... later, during load:
tourist.Deserialize(reader);
entityManager.SetComponentData(touristEntity, tourist);

Additional tips for modders: - Use this component in query-based ECS systems to find tourists tied to hotels, schedule departure logic, or free up hotel capacity at m_LeavingTime. - If you need to store additional state (arrival time, group size, origin), consider adding another component instead of modifying this core component to maintain compatibility. - Check related systems and components to learn the exact time unit used for m_LeavingTime and whether entity remapping is required during load.