Skip to content

Game.Citizens.Leisure

Assembly: Assembly-CSharp.dll
Namespace: Game.Citizens

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents a lightweight ECS component used by the citizen AI to track a leisure-related target and a frame limit. Stores the Entity reference for the target agent (e.g., a leisure location or another agent) and a uint indicating the last frame at which the leisure action is possible. Implements Colossal's ISerializable for reading/writing to the game save format and Unity ECS marker interfaces to be used as a component/query parameter.


Fields

  • public Entity m_TargetAgent
    This is the Entity reference representing the agent or leisure target associated with this leisure state. Commonly set to an Entity or Entity.Null when no target is assigned. Serialized first in the component's binary representation.

  • public uint m_LastPossibleFrame
    A frame index (unsigned int) recording the last frame where this leisure action was considered possible. Useful for timing/expiration checks in AI logic. Serialized second in the component's binary representation.

Properties

  • None.
    This struct exposes only public fields and does not define C# properties. It is intended to be a plain data component for ECS usage.

Constructors

  • public Leisure()
    The struct has the implicit parameterless constructor provided by C#. Fields default to Entity.Null (for Entity) and 0 (for uint) until initialized.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data in the following order: m_TargetAgent, then m_LastPossibleFrame. This method is used by the game's serialization pipeline (Colossal.Serialization.Entities). Ensure that any custom writer used follows the same ordering and types.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component data in the same order as Serialize: reads an Entity into m_TargetAgent, then reads a uint into m_LastPossibleFrame. The read order must match write order to preserve compatibility.

Notes: - The struct is blittable and small, making it suitable as a Unity ECS IComponentData. - When using with EntityManager or Systems, treat m_TargetAgent as an Entity handle; verify it is not Entity.Null before dereferencing. - The serialization methods rely on Colossal's entity-aware reader/writer to correctly map Entity instances when loading/saving.

Usage Example

// Add or update the Leisure component on an entity
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity citizenEntity = /* obtain or create entity */;

var leisure = new Game.Citizens.Leisure
{
    m_TargetAgent = targetEntity,       // some Entity or Entity.Null
    m_LastPossibleFrame = (uint)Time.frameCount + 600u // expire after 600 frames
};

if (em.HasComponent<Game.Citizens.Leisure>(citizenEntity))
{
    em.SetComponentData(citizenEntity, leisure);
}
else
{
    em.AddComponentData(citizenEntity, leisure);
}

Additional tips: - When serializing multiple components, keep consistent ordering across versions to maintain save compatibility. - Prefer checking for Entity.Null before accessing associated components of m_TargetAgent to avoid invalid entity access errors.