Skip to content

Game.Citizens.HealthProblem

Assembly: Assembly-CSharp
Namespace: Game.Citizens

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
HealthProblem is a lightweight component data struct used by the Citizens/health systems to represent a health-related event for an entity (citizen). It stores a reference to the originating event entity, an optional healthcare request entity, flags describing the problem, and a small timer. The struct implements serialization (ISerializable) with version-aware deserialization so older save versions remain compatible. It also implements IQueryTypeParameter for use in ECS queries.


Fields

  • public Entity m_Event
    Stores the entity that represents the health event (e.g., an incident or notification source). This is the primary reference to what caused the health problem.

  • public Entity m_HealthcareRequest
    Holds an Entity reference for an associated healthcare request (e.g., a request spawned to summon healthcare services). Defaults to Entity.Null in the provided constructor.

  • public HealthProblemFlags m_Flags
    Enum bitflags describing the problem (severity, type, or additional state). The actual enum definition is not included here; consult HealthProblemFlags for specific flag values.

  • public byte m_Timer
    A small timer/counter used by the health logic. Note: this field is only serialized/deserialized on or after the game save version that introduced healthcare notifications (checked via reader.context.version >= Version.healthcareNotifications).

Properties

  • None (the struct exposes fields directly; there are no C# properties in this type).

Constructors

  • public HealthProblem(Entity _event, HealthProblemFlags flags)
    Initializes a HealthProblem with the given event entity and flags. Sets m_HealthcareRequest to Entity.Null and m_Timer to 0.

Usage: - Use this constructor when creating a new health problem for a citizen or entity. After construction you can attach it as a component via the ECS EntityManager (AddComponentData) or set it on an existing component buffer/entity as appropriate.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component fields to the provided writer in the following order:
  • m_Event (Entity)
  • m_HealthcareRequest (Entity)
  • m_Flags (written as a single byte)
  • m_Timer (written as a byte)

This method ensures the compact storage of the component state for save/export.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component fields in the same order as Serialize. Important details:
  • Uses ref locals to read directly into m_Event and m_HealthcareRequest.
  • Reads a byte for flags and casts it back to HealthProblemFlags.
  • Only reads m_Timer from the reader if the save context version is >= Version.healthcareNotifications; otherwise m_Timer remains as previously set or default (0). This preserves compatibility with older save versions.

Notes: - Because flags are serialized as a byte, HealthProblemFlags values should fit within a byte or the serialization will truncate. - Implementing ISerializable makes this struct participate in the game's save/load system.

Usage Example

// Create a new health problem for an event entity and attach it to a citizen entity via ECS
var eventEntity = /* obtain or create the event entity */;
var citizenEntity = /* the citizen entity to attach the problem to */;

var healthProblem = new HealthProblem(eventEntity, HealthProblemFlags.None);

// Example using EntityManager (Unity.Entities)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(citizenEntity, healthProblem);

// Serialization is handled by the game's save system via ISerializable:
// writer.Write will be called by engine save logic (no manual writer usage required in most cases).