Game.Creatures.Pet
Assembly:
Namespace: Game.Creatures
Type: struct
Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a pet component used by the game's ECS (Entity Component System). This struct stores a reference to an associated household/entity and a set of bitwise flags describing pet state (stored in the PetFlags enum). It implements IComponentData so it can be added to entities, IQueryTypeParameter for use in ECS queries, and ISerializable for save/load support. The serialization writes only the flags field as an unsigned integer.
Fields
-
public Entity m_HouseholdPet
Reference to an Entity associated with this pet (for example, the household or owner entity). This is a raw Entity handle used by the ECS; it may be Entity.Null if no association exists. -
public PetFlags m_Flags
Bitfield describing pet-specific state (enum PetFlags). Defaults to PetFlags.None when constructed with the provided constructor. Serialized to/from a uint by the ISerializable implementation.
Properties
- This type has no properties. All data is exposed via public fields.
Constructors
public Pet(Entity householdPet)
Initializes a new Pet instance. Sets m_HouseholdPet to the provided entity and initializes m_Flags to PetFlags.None.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the pet flags to the provided writer as a uint. This is used by the game save/load serialization system. Only the m_Flags field is serialized by this implementation. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an unsigned integer from the provided reader and stores it into m_Flags (cast to PetFlags). This restores the pet's flag state during deserialization.
Usage Example
// Example: creating an entity with a Pet component and reading/updating flags
using Unity.Entities;
using Game.Creatures;
// obtain the EntityManager (depends on modding context)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
// create a new entity (or use an existing one)
Entity petEntity = entityManager.CreateEntity();
// suppose householdEntity is an Entity you already have (e.g., the owner household)
Entity householdEntity = /* obtain household entity */ Entity.Null;
// create and add the Pet component
var petComponent = new Pet(householdEntity);
entityManager.AddComponentData(petEntity, petComponent);
// later: read and modify flags
var pet = entityManager.GetComponentData<Pet>(petEntity);
// check flags (example, PetFlags enum values will vary)
if (pet.m_Flags == PetFlags.None)
{
// set a flag (example uses bitwise OR; replace SOME_FLAG with real enum member)
// pet.m_Flags |= PetFlags.SomeFlag;
// entityManager.SetComponentData(petEntity, pet);
}
// Serialization is handled by the game's save system via the ISerializable implementation:
// Serialize writes m_Flags as a uint and Deserialize restores it.
Notes and tips: - Because Pet implements IComponentData, it is suitable for use in jobs and ECS systems. The struct is blittable (contains an Entity and an enum-backed value) and cheap to copy. - The ISerializable implementation only persists m_Flags — m_HouseholdPet is not serialized by this component. If you need the household association to survive saves, ensure it is represented elsewhere in the ECS save data or handle it explicitly. - Consult the PetFlags enum definition (in the same assembly) to see available flag values and semantics.