Game.Pathfind.PathfindActionData
Assembly:
Assembly-CSharp.dll
Namespace: Game.Pathfind
Type:
struct (implements System.IDisposable)
Base:
System.ValueType, System.IDisposable
Summary:
PathfindActionData is a native-memory backed container used to hold all data required for a single pathfinding action in the game's pathfinding system. It stores start and end targets, results, optional path information, pathfinding parameters, origin/destination setup types, and the current action state. It uses Unity.Collections.LowLevel.Unsafe.UnsafeList for low-level, manually managed storage and therefore must be disposed explicitly to free native memory. The constructor allocates lists based on provided counts and flags; Dispose frees any created native lists.
Fields
-
public UnsafeList<PathTarget> m_StartTargets
Holds the start targets for the pathfinding action. When constructed with startCount != 0 an UnsafeList with capacity startCount is allocated and its Length set to startCount; otherwise this field is left as the default (not created). Elements are uninitialized and must be populated by the caller after construction. -
public UnsafeList<PathTarget> m_EndTargets
Holds the end/destination targets. Similar allocation behavior to m_StartTargets: allocated and its Length set to endCount when endCount != 0, otherwise left default. -
public UnsafeList<PathfindResult> m_Result
A list to store the pathfinding result(s). Always allocated in the constructor with an initial capacity of 1 (using the provided allocator). Must be disposed to free native memory. -
public UnsafeList<PathfindPath> m_Path
An optional list that stores the computed path(s). It is allocated with an initial capacity of 100 unless the PathfindParameters indicate the PathfindFlags.IgnorePath flag is set, in which case this field is left as the default (not created). -
public PathfindParameters m_Parameters
Holds the pathfinding parameters used for this action (flags, heuristics, cost modifiers, etc.). Used to decide behavior such as whether to allocate m_Path. -
public SetupTargetType m_OriginType
Indicates the setup/target type used for the origin (how start targets are interpreted). -
public SetupTargetType m_DestinationType
Indicates the setup/target type used for the destination (how end targets are interpreted). -
public PathfindActionState m_State
Current state of the action. The constructor initializes this to PathfindActionState.Pending.
Properties
- None. This struct exposes only public fields and implements IDisposable.
Constructors
public PathfindActionData(int startCount, int endCount, Allocator allocator, PathfindParameters parameters, SetupTargetType originType, SetupTargetType destinationType)
Allocates and initializes native lists according to the provided counts and parameters:- If startCount != 0, allocates m_StartTargets with capacity startCount and sets its Length to startCount. Otherwise leaves m_StartTargets default.
- If endCount != 0, allocates m_EndTargets with capacity endCount and sets its Length to endCount. Otherwise leaves m_EndTargets default.
- Allocates m_Result with capacity 1.
- Allocates m_Path with capacity 100 unless parameters.m_PathfindFlags has PathfindFlags.IgnorePath set, in which case m_Path is left default (not created).
- Stores the provided parameters, originType, and destinationType.
- Sets m_State to PathfindActionState.Pending.
Notes: - UnsafeList elements are not initialized by the constructor — fields like m_StartTargets[i] must be populated by the caller before use. - The provided Allocator (e.g., Allocator.Temp, Allocator.Persistent) determines lifetime and must be chosen appropriately for how long the data will be used.
Methods
public void Dispose()
Disposes any created UnsafeList instances to free native memory:- Disposes m_StartTargets if IsCreated.
- Disposes m_EndTargets if IsCreated.
- Disposes m_Result (always allocated in constructor).
- Disposes m_Path if IsCreated.
Always call Dispose when done with the PathfindActionData instance (or use a try/finally or using pattern) to avoid native memory leaks.
Usage Example
using Unity.Collections;
using Game.Pathfind;
// Example 1: explicit create/use/dispose
var allocator = Allocator.Persistent;
var parameters = default(PathfindParameters); // set up parameters appropriately
parameters.m_PathfindFlags = 0; // or set PathfindFlags.IgnorePath as needed
PathfindActionData data = default;
try {
data = new PathfindActionData(startCount: 2, endCount: 1, allocator: allocator,
parameters: parameters,
originType: SetupTargetType.Node,
destinationType: SetupTargetType.Node);
// Populate start/end targets before use:
if (data.m_StartTargets.IsCreated) {
// e.g. data.m_StartTargets[0] = new PathTarget(...);
// e.g. data.m_StartTargets[1] = new PathTarget(...);
}
if (data.m_EndTargets.IsCreated) {
// e.g. data.m_EndTargets[0] = new PathTarget(...);
}
// Invoke pathfinding system with 'data'...
}
finally {
// Ensure native memory is freed
data.Dispose();
}
// Example 2: 'using' pattern (C# 8+) — disposing the struct at end of scope
using var actionData = new PathfindActionData(0, 0, Allocator.Temp, default, SetupTargetType.None, SetupTargetType.None);
// Use actionData...
// actionData.Dispose() called automatically at end of scope.
Additional notes: - Check each UnsafeList's IsCreated property before attempting to read or Dispose it. - Because UnsafeList stores native memory and elements are not zero-initialized by the constructor, initialize elements explicitly to avoid undefined data being processed by pathfinding code. - Choose the Allocator (Temp, TempJob, Persistent) to match the intended lifetime; incorrect choice can cause crashes or leaks.