Game.Pathfind.PathfindResult
Assembly: Assembly-CSharp
Namespace: Game.Pathfind
Type: struct
Base: System.ValueType
Summary:
A plain data container used to return the outcome of a pathfinding request. Holds references to origin and destination entities, measured metrics for the computed route (distance, duration, cost), path metadata (length, graph traversal count), which pathfinding methods were used, and an error code describing success or failure. Designed to be a compact, copyable value type suitable for use in game systems and jobs.
Fields
-
public Unity.Entities.Entity m_Origin
Entity that represents the start point of the computed path. May be Entity.Null when not set. -
public Unity.Entities.Entity m_Destination
Entity that represents the target/end point of the computed path. May be Entity.Null when not set. -
public float m_Distance
Numeric distance of the computed path. Units are the game's world units — typically used to reason about path length or for gameplay metrics. -
public float m_Duration
Estimated travel time along the computed path (or the time taken to compute the path depending on calling convention). Interpret according to the calling system's documentation. -
public float m_TotalCost
Aggregate cost metric used by the pathfinding algorithm (for example weighted cost combining distance, penalties, or other heuristic costs). Useful for comparing alternative routes. -
public PathMethod m_Methods
Flags or enum value describing which pathfinding method(s) were used to compute the result (the PathMethod enum defines available algorithms/strategies). -
public int m_GraphTraversal
Count of graph nodes or edges traversed during the pathfinding operation — a diagnostic metric that can indicate algorithm effort. -
public int m_PathLength
Number of steps/waypoints in the computed path. Zero or negative values typically indicate no valid path. -
public ErrorCode m_ErrorCode
Enumeration value indicating success or the kind of failure encountered (e.g., no path found, invalid inputs). Always check this before using path metrics.
Properties
- This struct exposes no properties. All data is stored in public fields and should be read/written directly.
Constructors
public PathfindResult()
Structs in C# have an implicit default parameterless constructor that initializes numeric fields to zero, enum fields to their default (usually zero), and Entity fields to Entity.Null. Populate fields explicitly after construction when required.
Methods
- This type defines no methods.
Usage Example
// Create and populate a result
PathfindResult result = new PathfindResult();
result.m_Origin = originEntity;
result.m_Destination = destinationEntity;
// After invoking the pathfinder, the system fills the result:
if (result.m_ErrorCode == ErrorCode.Success)
{
Debug.Log($"Path found: distance={result.m_Distance}, duration={result.m_Duration}, steps={result.m_PathLength}");
// Use result.m_TotalCost / result.m_Methods as needed
}
else
{
Debug.LogWarning($"Pathfinding failed: {result.m_ErrorCode}");
}
Notes: - Because PathfindResult is a value type, it is copied when passed between methods or job data structures. For large-scale usage in jobs or ECS, prefer passing by reference where appropriate to avoid unnecessary copies. - Always check m_ErrorCode before relying on other fields — when an error occurs, metric fields may be zero or contain partial data.