Skip to content

Game.Pathfind.PathOwner

Assembly:
{{ Likely contained in the game's runtime assembly where other Pathfind types live (e.g. Assembly-CSharp or a Game assembly). Confirm in your build if needed. }}

Namespace:
Game.Pathfind

Type:
struct PathOwner

Base:
IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents ownership/state information for a path element inside the pathfinding system. Holds an element index (m_ElementIndex) that identifies the backing path data and a set of PathFlags (m_State) describing the path's lifecycle (e.g. Pending, Obsolete, etc.). Implements IComponentData so it can be attached to ECS entities, IQueryTypeParameter for query usage, and ISerializable to control binary persistence. On deserialization any Pending flag is converted to Obsolete to avoid resurrecting in-flight requests when loading state.


Fields

  • public System.Int32 m_ElementIndex
    Holds the index of the path element in the path storage (an integer identifier for the path resource). Written/read as a 32-bit int during serialization.

  • public PathFlags m_State
    Flags describing the path's state (type PathFlags). Serialized as a 16-bit unsigned value (ushort). On Deserialize, if the Pending flag is present it is cleared and replaced with Obsolete to prevent reusing pending operations across save/load.

Properties

  • None.
    This struct exposes its data via public fields rather than properties.

Constructors

  • public PathOwner(PathFlags state)
    Initializes a PathOwner with m_ElementIndex = 0 and m_State set to the provided state. Useful when you want to create an owner for a yet-unallocated element or to represent a purely stateful owner.

  • public PathOwner(int elementIndex, PathFlags state)
    Initializes a PathOwner with the supplied element index and state. Use this when you already have an element index to associate.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component to a writer for persistence. Writes m_ElementIndex as an int, then writes m_State cast to ushort. This compactly stores the state flags as 16 bits.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component back from a reader. Reads the element index into m_ElementIndex, then reads a ushort and casts to PathFlags for m_State. After reading it normalizes flags: if PathFlags.Pending is set, it is removed and PathFlags.Obsolete is set instead. This prevents pending (in-flight) path requests from being treated the same on load — they are marked obsolete so they can be re-requested or cleaned up instead of left pending.

Notes: - Implemented to conform to the game's serialization system (Colossal.Serialization.Entities). - The Pending -> Obsolete conversion is intentional to avoid restoring transient pending operations across save/load boundaries.

Usage Example

// Create a new owner with a state but no element index
var owner = new PathOwner(PathFlags.None);

// Create an owner with a known element index and a state
var ownerWithIndex = new PathOwner(1234, PathFlags.Obsolete);

// Add as a component to an entity (ECS example)
entityManager.AddComponentData(entity, ownerWithIndex);

// Serialization will write the int element index and then the state as a ushort.
// On load, any Pending flag will be replaced by Obsolete by the Deserialize implementation.

{{ Additional tips: - When inspecting saved data or debugging serialization, remember the state field is stored as a 16-bit value. - If you rely on Pending semantics, be careful: loading a save will clear Pending and set Obsolete automatically. If you need to re-issue pending path requests after load, implement logic to detect Obsolete and re-request as needed. }}