Skip to content

Game.Pathfind.PathInformation

Assembly: Assembly-CSharp (typical for Cities: Skylines 2 game code)
Namespace: Game.Pathfind

Type: struct (value type)

Base: System.ValueType; implements IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
Represents the stored result/meta information for a pathfinding request between two Entities. Contains origin and destination Entity references, numeric metrics (distance, duration, total cost), the pathfinding methods used (bitmask), and state flags describing the lifecycle of the path result. The struct supports custom binary serialization/deserialization via ISerializable and is suitable for use as a Unity ECS component (IComponentData / IQueryTypeParameter).


Fields

  • public Entity m_Origin
    Entity reference for the path origin.

  • public Entity m_Destination
    Entity reference for the path destination.

  • public float m_Distance
    Total path distance as a floating-point value.

  • public float m_Duration
    Estimated traversal duration (time) for the path.

  • public float m_TotalCost
    Total computed cost for the path; serialized/deserialized only if the save/context version includes Version.totalPathfindCost.

  • public PathMethod m_Methods
    Bitmask/enum indicating which pathfinding method(s) were used to compute the path. Written as a ushort during serialization and only read when the save/context version >= Version.usedPathfindMethods.

  • public PathFlags m_State
    Flags describing the path state (e.g., Pending, Obsolete, Complete). Stored as a ushort in serialized data if reader version supports Version.pathfindState. On deserialization, Pending entries are converted to Obsolete to avoid restoring transient pending work between sessions.

Properties

  • This struct exposes no public C# properties. All data members are public fields; accessors are direct.

Constructors

  • public PathInformation()
    Implicit parameterless constructor (default struct constructor). When created with the default constructor, numeric fields are zeroed and enum/Entity fields default to their zero values. Initialize fields explicitly before use when required.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the struct to the provided writer. The implementation writes, in order:
  • m_Origin (Entity)
  • m_Destination (Entity)
  • m_Distance (float)
  • m_Duration (float)
  • m_TotalCost (float)
  • m_Methods (written as ushort)
  • m_State (written as ushort) Note: the method performs direct writes for all fields; callers should ensure writer/context version is compatible with how they'll be read back.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the struct from the provided reader. The method reads origin, destination, distance, and duration unconditionally. It conditionally reads:

  • m_TotalCost if reader.context.version >= Version.totalPathfindCost
  • m_Methods if reader.context.version >= Version.usedPathfindMethods (reads ushort and casts to PathMethod)
  • m_State if reader.context.version >= Version.pathfindState (reads ushort and casts to PathFlags) After reading, if the m_State has the Pending flag set, the implementation clears Pending and sets the Obsolete flag instead. This prevents restoring transient "pending" path requests as pending on load; they become obsolete and can be recalculated.

Usage Example

// Example: create and serialize a PathInformation instance
PathInformation info = new PathInformation
{
    m_Origin = originEntity,
    m_Destination = destinationEntity,
    m_Distance = 123.45f,
    m_Duration = 67.89f,
    m_TotalCost = 200.0f,
    m_Methods = PathMethod.AStar,    // example enum value
    m_State = PathFlags.Complete     // example enum value
};

// Serialize using a writer that implements IWriter
info.Serialize(writer);

// Example: deserialize
PathInformation loaded;
loaded.Deserialize(reader);

// Note: when deserializing older save versions, TotalCost / Methods / State
// may be omitted and will remain default. Pending states will be converted
// to Obsolete automatically by Deserialize.

Additional notes: - This struct is designed to be used inside the Unity Entities ECS world as a component (IComponentData) and as a query parameter (IQueryTypeParameter). - The Version checks refer to the game's serialization versioning constants (Version.totalPathfindCost, Version.usedPathfindMethods, Version.pathfindState). When creating mod code that relies on these fields, be mindful of compatibility with older save versions. - The m_State Pending -> Obsolete conversion on deserialization ensures transient in-progress path computations are not resurrected as active after loading a save; code that relies on Pending should requeue or recompute paths as needed.