Skip to content

Game.Vehicles.Hearse

Assembly: Game
Namespace: Game.Vehicles

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the data component for a hearse vehicle in the ECS (Unity.Entities) used by the game. Stores the hearse state flags, the target corpse and (optionally, depending on save version) a target service request entity, and a timer used while traversing path elements. Implements custom binary serialization/deserialization for saving/loading component state.


Fields

  • public HearseFlags m_State
    Holds the hearse's state flags (type HearseFlags). Serialized as a uint. Represents the current state (e.g., idle, en route, delivering).

  • public Entity m_TargetCorpse
    Entity reference to the corpse the hearse is currently assigned to. Serialized and deserialized as an Entity.

  • public Entity m_TargetRequest
    Entity reference to the service request associated with the hearse (introduced in a later save version). Deserialized only when the reader context version is >= Version.reverseServiceRequests2. Serialized when writing.

  • public float m_PathElementTime
    Floating-point timer storing the elapsed time inside the current path element. Used by movement/path-following logic. Serialized and deserialized as a float.

Properties

  • None.

Constructors

  • public Hearse(Entity targetCorpse, HearseFlags state)
    Creates a new Hearse component instance. Initializes:
  • m_State = state
  • m_TargetCorpse = targetCorpse
  • m_TargetRequest = Entity.Null
  • m_PathElementTime = 0f

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data in a stable order:
  • Writes m_State as a uint.
  • Writes m_TargetCorpse (Entity).
  • Writes m_TargetRequest (Entity).
  • Writes m_PathElementTime (float).
    This method is called when saving component data; it expects the writer to support writing the primitive types and Entity.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component data (matching the order used in Serialize):

  • Reads a uint into a temporary value (the state).
  • Reads m_TargetCorpse (Entity) unconditionally.
  • Reads m_TargetRequest (Entity) only if reader.context.version >= Version.reverseServiceRequests2. This preserves backward compatibility with older save versions that do not include the request field.
  • Reads m_PathElementTime (float).
  • Converts the previously read uint value into HearseFlags and assigns it to m_State.
    Note: The version check is important to avoid misreading older save formats.

Usage Example

// Constructing a hearse component for an entity (example usage)
Entity corpseEntity = /* obtain corpse entity */;
Hearse myHearse = new Hearse(corpseEntity, HearseFlags.EnRoute);
myHearse.m_PathElementTime = 0f;

// Adding to an entity using Unity.Entities (example)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity hearseEntity = em.CreateEntity();
// add other required components for a vehicle...
em.AddComponentData(hearseEntity, myHearse);

// During serialization the component's Serialize method will be invoked by the
// game's save system (IWriter implementation provided by engine code).

{{ Additional notes: - This struct is a plain data component for Unity's ECS. It does not contain behavior; systems operating on Hearse components implement the hearse logic (movement, picking up corpses, fulfilling requests). - HearseFlags and Version.reverseServiceRequests2 are defined elsewhere in the game's codebase — check their definitions for exact flag meanings and save-version semantics. - m_TargetRequest being conditionally read ensures compatibility with older saved games where that field did not exist. }}