Game.Pathfind.PathfindAction
Assembly:
Game (Cities: Skylines 2 game code)
Namespace:
Game.Pathfind
Type:
struct
Base:
System.ValueType, implements System.IDisposable
Summary:
PathfindAction is a lightweight wrapper around a NativeReference
Fields
public Unity.Collections.NativeReference<PathfindActionData> m_Data
Holds the native reference to the PathfindActionData instance. This is the owned native memory that must be disposed. It is created in the constructor with the provided Allocator and contains the pathfinding buffers/metadata used by the pathfinding system.
Properties
-
public ref PathfindActionData data { get }
Returns a ref to the PathfindActionData stored in the NativeReference (via ValueAsRef()). Use this when you need to modify the underlying PathfindActionData in place. Because it returns a ref to native memory, care must be taken to not use the reference after Dispose() has been called. -
public PathfindActionData readOnlyData { get }
Returns a value copy of the PathfindActionData (via Value). Use this when you only need to read data and want a safe copy that does not depend on native memory lifetime.
Constructors
public PathfindAction(int startCount, int endCount, Allocator allocator, PathfindParameters parameters, SetupTargetType originType, SetupTargetType destinationType)
Creates and initializes the internal NativeReferenceby constructing a new PathfindActionData using the supplied start/end counts, allocator, parameters, and setup target types. The allocator parameter determines the lifetime/behavior of the native allocation (e.g., Temp, TempJob, Persistent) and should be chosen appropriately for the usage pattern. If you allocate with a persistent allocator, you must call Dispose() to free memory.
Methods
public void Dispose()
Disposes the contents of the PathfindAction. This first calls Dispose() on the contained PathfindActionData (to free any internal native buffers) and then disposes the NativeReference itself. After calling Dispose(), the native memory is released and further access to data or readOnlyData is invalid.
Usage Example
// Example: create a PathfindAction, use it, then dispose.
var allocator = Unity.Collections.Allocator.TempJob; // choose appropriate allocator
var parameters = new PathfindParameters(...); // construct as required
var action = new PathfindAction(startCount: 128, endCount: 128, allocator, parameters, originType: SetupTargetType.SomeType, destinationType: SetupTargetType.SomeType);
try
{
// modify underlying data via ref
ref var d = ref action.data;
// d.SomeField = ...; // set up pathfind request data
// read a safe copy
var snapshot = action.readOnlyData;
// use snapshot for read-only operations
}
finally
{
// ensure native memory is released
action.Dispose();
}
Notes and best practices: - Always match the Allocator you pass to the constructor with an appropriate lifetime and ensure Dispose() is called to avoid native memory leaks. - Use data (by-ref) for in-place modifications and performance-critical updates; use readOnlyData when a copy is sufficient or safer. - PathfindActionData likely contains its own native buffers; disposing PathfindAction will dispose those as well. Refer to PathfindActionData documentation for details of contained buffers and their usage.