Skip to content

Game.HouseholdAnimal

Assembly: Assembly-CSharp
Namespace: Game.Citizens

Type: struct

Base: IBufferElementData, IEquatable, IEmptySerializable

Summary:
Represents a buffer element that stores a reference to a household pet Entity for a citizen/household. The struct is intended for use with Unity's ECS DynamicBuffer (IBufferElementData). It is marked with [InternalBufferCapacity(1)] to optimize small buffers by providing an inline capacity of one element before separate heap allocation. Implements IEquatable for value equality and IEmptySerializable for Colossal serialization compatibility.


Fields

  • public Unity.Entities.Entity m_HouseholdPet
    Holds the Entity reference to the household pet. This is the value used for equality and hashing.

  • Attribute: [InternalBufferCapacity(1)] (applies to the struct)
    Indicates that a DynamicBuffer will have an inline storage capacity of 1 element before allocating out-of-line storage.

Properties

  • This type exposes no properties. It only contains the public field m_HouseholdPet.

Constructors

  • public HouseholdAnimal(Unity.Entities.Entity householdPet)
    Initializes a new HouseholdAnimal with the provided pet Entity.

Methods

  • public bool Equals(HouseholdAnimal other)
    Implements IEquatable. Returns true if the contained m_HouseholdPet Entity equals the other instance's m_HouseholdPet.

  • public override int GetHashCode()
    Returns the hash code of the contained m_HouseholdPet Entity. Suitable for use in hashed containers and for equality checks.

Usage Example

// Example: attaching a household pet buffer to a household entity and adding a pet Entity.
using Unity.Entities;
using Game.Citizens;

public partial class HouseholdPetSystem : SystemBase
{
    protected override void OnUpdate()
    {
        var em = EntityManager;
        Entity householdEntity = /* obtain household entity */;
        Entity petEntity = /* obtain/create pet entity */;

        // Ensure the household has a DynamicBuffer<HouseholdAnimal>
        var buffer = em.GetBuffer<HouseholdAnimal>(householdEntity);
        buffer.Add(new HouseholdAnimal(petEntity));

        // Reading back
        foreach (var element in buffer)
        {
            Entity pet = element.m_HouseholdPet;
            // use pet Entity...
        }
    }
}

Notes: - Because m_HouseholdPet is a raw Entity, users must ensure referenced Entities remain valid (not destroyed) or handle invalid references appropriately. - The struct is lightweight and suitable for storage in DynamicBuffer columns on entities (e.g., one-to-many pet relationships).