Game.Citizens.Household
Assembly: Assembly-CSharp
Namespace: Game.Citizens
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents a household component used by the citizen systems. Stores simple household state: flags, current stored resources, and the consumption-per-day value. Implements the game's binary serialization callbacks so it can be persisted and loaded across versions; also functions as an ECS component (IComponentData) and a query parameter type for entity queries.
Fields
-
public HouseholdFlags m_Flags
Holds bit flags describing the household's state (see HouseholdFlags enum). Serialized as a single byte. -
public int m_Resources
Current stored resources for the household. Serialized as a 32-bit integer. During deserialization negative values are clamped to 0. -
public short m_ConsumptionPerDay
How many resources this household consumes per day. Serialized as a 16-bit integer.
Properties
- None This struct exposes only public fields and does not declare C# properties.
Constructors
- Implicit default constructor No explicit constructors are defined; the default parameterless value-type constructor is used.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the household data to a writer in this order:- m_Flags cast to a byte
- m_Resources (int)
- m_ConsumptionPerDay (short)
This is used by the game's persistence pipeline to store household state.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads household data from a reader. Behavior:- Reads a byte into a local value representing flags.
- Compatibility handling: if reader.context.version < Version.householdRandomSeedRemoved, reads and discards an extra uint (this was the removed random-seed field retained for older save/load compatibility).
- Reads m_Resources (into the struct field by ref).
- Reads m_ConsumptionPerDay (into the struct field by ref).
- Assigns m_Flags from the previously read byte.
- Ensures m_Resources is not negative; if negative it is set to 0.
This method ensures forward/backward compatibility with older save formats that included a removed household random seed.
Usage Example
// Create and initialize a household component
var household = new Game.Citizens.Household
{
m_Flags = HouseholdFlags.None,
m_Resources = 120,
m_ConsumptionPerDay = 5
};
// Example pseudo-serialization (actual writer implementation depends on game engine)
// writer must implement IWriter
household.Serialize(writer);
// Example pseudo-deserialization (actual reader implementation depends on game engine)
// household.Deserialize(reader);
// After Deserialize, m_Resources is guaranteed to be >= 0 even if the save had a negative value.
// Compatibility: older save versions that contained a removed 'random seed' field are handled
// by the version check against Version.householdRandomSeedRemoved.