Skip to content

Game.Pathfind.AvailabilityActionData

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Pathfind

Type:
struct

Base:
System.ValueType (implements System.IDisposable)

Summary:
AvailabilityActionData is a small value-type container used by the pathfinding availability subsystem. It groups the native/unsafe collections required to run an "availability" action: queues of sources (path targets) and providers, a results list, the parameters for the availability query, and the action state. All collections are Unity.Collections low-level (unsafe) containers that allocate unmanaged memory and must be disposed to avoid leaks. The constructor allocates these containers with a specified Allocator and sets the initial state to Pending.


Fields

  • public UnsafeQueue<PathTarget> m_Sources
    Holds a queue of PathTarget items representing source targets to be checked for availability. This is an unsafe/native queue optimized for low-level or jobified use. It must be allocated with an Allocator and disposed when no longer needed.

  • public UnsafeQueue<AvailabilityProvider> m_Providers
    Holds a queue of AvailabilityProvider items—entities or data providers that can satisfy availability queries. Like m_Sources, it is an unsafe/native queue and must be disposed.

  • public UnsafeList<AvailabilityResult> m_Results
    Stores the results of availability checks. Constructed with an initial capacity of 100 in the provided constructor. This UnsafeList uses unmanaged memory and must be disposed.

  • public AvailabilityParameters m_Parameters
    Configuration struct (or data) that defines how the availability checks should be performed (e.g., filters, limits, search options). It is copied into this container on construction.

  • public PathfindActionState m_State
    Tracks the lifecycle state of the action (e.g., Pending, Running, Completed). The constructor sets this to PathfindActionState.Pending.

Properties

  • None (no managed properties are defined on this struct)

Constructors

  • public AvailabilityActionData(Allocator allocator, AvailabilityParameters parameters)
    Constructs and initializes the native containers:
  • Allocates m_Sources as an UnsafeQueue using the supplied allocator.
  • Allocates m_Providers as an UnsafeQueue using the supplied allocator.
  • Allocates m_Results as an UnsafeList with initial capacity 100 and the supplied allocator.
  • Copies the provided parameters into m_Parameters.
  • Sets m_State to PathfindActionState.Pending.

Notes: - The provided Allocator must be appropriate for the intended lifetime (e.g., Allocator.TempJob for short-lived job allocations, Allocator.Persistent for long-lived). - These allocations create unmanaged memory; failure to Dispose will leak memory.

Methods

  • public void Dispose()
    Disposes the three native containers: m_Sources, m_Providers, and m_Results. Calling Dispose releases unmanaged memory allocated by those containers. Ensure the instance was properly constructed before calling Dispose (calling Dispose on a default or uninitialized struct instance may be invalid). Prefer calling Dispose in a finally block or using a deterministic cleanup pattern to avoid leaks.

Additional considerations: - The contained UnsafeQueue/UnsafeList types are low-level and may not be thread-safe by themselves; use appropriate synchronization or job-safe patterns when accessing them from multiple threads or jobs. - If using these containers in jobs, choose an allocator compatible with job lifetimes (e.g., Allocator.TempJob) and follow Unity's rules for passing native containers into jobs.

Usage Example

using Unity.Collections;
using System;

AvailabilityParameters parameters = new AvailabilityParameters { /* configure */ };
AvailabilityActionData action = new AvailabilityActionData(Allocator.TempJob, parameters);

try
{
    // Enqueue sources/providers, run availability checks, read results...
    // e.g. action.m_Sources.Enqueue(somePathTarget);
    //      action.m_Providers.Enqueue(someProvider);
}
finally
{
    // Always dispose to free unmanaged memory
    action.Dispose();
}

Additional tip: for longer-lived data use Allocator.Persistent and ensure Dispose is called when the data is truly no longer required (for example, during mod unload or manager shutdown).