Game.Citizens.HouseholdMember
Assembly:
Game (assembly containing game ECS components; often part of the game's primary assembly / Assembly-CSharp)
Namespace: Game.Citizens
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents an ECS component that associates an entity (typically a citizen or person entity) with its household entity. The component stores a single Unity.Entities.Entity reference (m_Household). It implements ISerializable to allow the household reference to be written/read by the game's serialization system and IQueryTypeParameter to be usable as a query parameter in ECS queries. This component is a lightweight linking component used by household/citizen logic to resolve household-level data (address, inventory, members list, etc.). The m_Household field may be Entity.Null when not assigned.
Fields
public Unity.Entities.Entity m_Household
Stores the Entity reference to the household this member belongs to. Can be Entity.Null if not set. When serialized/deserialized, the entity reference is written/read through the Colossal.Serialization system so references remain valid across load/save.
{{ The field is public to allow direct component data access via EntityManager/GetComponentData/AddComponentData/etc. Ensure you check for Entity.Null before dereferencing the household and prefer using ECS-safe patterns (e.g., queries or entity managers) when accessing the referenced entity. }}
Properties
- This type defines no properties.
{{ Use the public field directly. If you need property-like behavior, wrap the component in accessor methods in systems or helper classes. }}
Constructors
public HouseholdMember()
(default value-type constructor)
{{ As a struct, HouseholdMember uses the default value constructor. Create a component instance via object initializer, e.g. new HouseholdMember { m_Household = householdEntity }. There are no custom constructors in the source. }}
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
{{ Writes the m_Household Entity reference to the provided writer. The writer implementation handles entity reference remapping for save/load. }} -
public void Deserialize<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
{{ Reads an Entity reference into m_Household from the provided reader. The reader resolves entity references back to runtime entities after load. }}
Additional notes: - IQueryTypeParameter is a marker allowing this struct to be used as a parameter type in ECS queries. It has no runtime method requirements here. - Serialization methods are simple pass-throughs for the single Entity field; the Colossal.Serialization.Entities machinery handles ID remapping and versioning concerns.
Usage Example
// Example: assign a household entity to a citizen/member entity.
using Unity.Entities;
using Game.Citizens;
// create or obtain an EntityManager or EntityCommandBuffer
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
// Assume householdEntity and citizenEntity were created earlier
Entity householdEntity = entityManager.CreateEntity();
Entity citizenEntity = entityManager.CreateEntity();
// Add the HouseholdMember component to the citizen, linking to the household
entityManager.AddComponentData(citizenEntity, new HouseholdMember { m_Household = householdEntity });
// Later, in a system, read the household:
var member = entityManager.GetComponentData<HouseholdMember>(citizenEntity);
if (member.m_Household != Entity.Null)
{
// operate on household entity (read other components, etc.)
}
{{ This component is intended for use within ECS systems that manage citizen/household relationships. When saving/loading, the Serialize/Deserialize methods ensure the entity link is preserved. Always check for Entity.Null before accessing the referenced entity. }}