Game.Pathfind.AvailabilityAction
Assembly: Assembly-CSharp
Namespace: Game.Pathfind
Type: struct
Base: System.ValueType, implements System.IDisposable
Summary:
AvailabilityAction is a small value-type wrapper that owns a NativeReference to an AvailabilityActionData instance. It is used by the pathfinding/availability systems to allocate and hold AvailabilityActionData in native memory (using Unity.Collections.Allocator). The struct provides a ref-returning property to access the contained AvailabilityActionData and implements IDisposable to release both the contained data and the NativeReference itself. Ensure Dispose is called to avoid native memory leaks.
Fields
public NativeReference<AvailabilityActionData> m_Data
Holds the native reference that points to an AvailabilityActionData instance allocated with the provided Allocator. The NativeReference owns the memory backing the AvailabilityActionData; freeing that memory is the responsibility of Dispose().
Properties
public ref AvailabilityActionData data { get; }
Returns a by-ref reference to the AvailabilityActionData instance stored inside m_Data via m_Data.ValueAsRef(). Use this ref to read or modify the native data in-place without additional copies.
Constructors
public AvailabilityAction(Allocator allocator, AvailabilityParameters parameters)
Allocates a new AvailabilityActionData with the given allocator and parameters, and stores it in a NativeReference allocated with the same allocator. The allocated NativeReference and the enclosed AvailabilityActionData must be released by calling Dispose() on the AvailabilityAction instance.
Methods
public void Dispose()
Frees resources in reverse order: calls data.Dispose() to allow the contained AvailabilityActionData to release any native resources it owns, then disposes the NativeReference (m_Data.Dispose()) to free the memory holding the AvailabilityActionData itself. Always call Dispose() when the AvailabilityAction is no longer needed to avoid native-memory leaks.
Usage Example
// Create using a persistent allocator (or another appropriate allocator for your usage)
Allocator allocator = Allocator.Persistent;
AvailabilityParameters parameters = new AvailabilityParameters(/* ... */);
// Construct the AvailabilityAction which allocates native memory
var availabilityAction = new AvailabilityAction(allocator, parameters);
// Access the contained data by ref to modify/read in-place
ref AvailabilityActionData dataRef = ref availabilityAction.data;
dataRef.SomeField = 42; // example field mutation
// When finished, release native resources
availabilityAction.Dispose();
Notes and tips: - Because this uses Unity.Collections.NativeReference and native allocation, be careful about which Allocator you choose (Temporary/TempJob/Persistent) and match lifetime responsibilities accordingly. - If you intend to use the NativeReference or the contained data inside a Unity job, ensure proper safety handles and job synchronization; NativeReference can be used in jobs but you must follow Unity Collections safety rules. - Always call Dispose() on AvailabilityAction to avoid leaking native memory.