Game.Citizens.HouseholdPet
Assembly: Game
Namespace: Game.Citizens
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: HouseholdPet is a small ECS component representing a pet belonging to a household. It stores a reference to the household Entity and implements Colossal Serialization interfaces so the component can be serialized/deserialized when saving/loading game state. It is usable in Unity's DOTS/ECS systems (can be added to entities, queried, and processed by jobs/systems).
Fields
public Unity.Entities.Entity m_Household
This field holds the Entity reference of the household this pet belongs to. It should be set to the household entity when the pet component is created/added to an entity. When serialized, this Entity value is written/read via the provided IWriter/IReader.
Properties
- None
This struct exposes no C# properties; only the public field m_Household is present.
Constructors
public HouseholdPet()
Uses the default value-type constructor (struct). No explicit constructors are defined in source — create instances using object initializer syntax or default initialization.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the contained Entity (m_Household) to the provided writer. Used by the game's serialization pipeline to persist the reference. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an Entity value into m_Household from the provided reader. Used when loading saved state to restore the household link.
Notes: - The generic constraints ensure the methods work with any concrete writer/reader implementation that implements the respective interfaces from Colossal.Serialization.Entities. - Because this is a value-type ECS component implementing ISerializable, the serialization callbacks are simple and only cover the single Entity field.
Usage Example
// Add the component to an entity and set its household reference
Entity petEntity = entityManager.CreateEntity();
Entity householdEntity = /* obtain household entity */;
var pet = new Game.Citizens.HouseholdPet { m_Household = householdEntity };
entityManager.AddComponentData(petEntity, pet);
// Example of how serialization methods are defined (handled by the engine's serializer):
// writer.Write(pet.m_Household);
// reader.Read(out pet.m_Household);
// Querying pets in a system (example usage as query type parameter)
Entities.ForEach((Entity e, ref Game.Citizens.HouseholdPet pet) =>
{
// process pet, e.g. get the household entity reference:
Entity ownerHousehold = pet.m_Household;
}).Schedule();
{{ Additional notes: - Treat the m_Household Entity as the authoritative link — ensure it remains valid (not destroyed) or check its existence before use. - Because this is a plain struct with a single Entity field, copying and assignment are cheap; avoid storing stale Entity references across domain reloads or after entity destruction. }}