Skip to content

Game.Pathfind.CreateAction

Assembly:
(not specified)

Namespace: Game.Pathfind

Type: struct

Base: System.ValueType, System.IDisposable

Summary:
CreateAction is a lightweight container that owns a NativeArray. It is used to allocate and hold per-action data for pathfinding create operations. You construct it with a desired length and a Unity.Collections.Allocator, use the contained NativeArray (m_CreateData) to read/write entries, and then Dispose() it to free the native memory. Be careful with copies of this struct — the NativeArray field refers to shared native memory, so disposing one copy will affect others that reference the same buffer.


Fields

  • public Unity.Collections.NativeArray<CreateActionData> m_CreateData
    Holds the allocated CreateActionData elements. The array is created in the constructor with the requested size and allocator. The memory must be explicitly released by calling Dispose() on the CreateAction (or by disposing the NativeArray directly). Check m_CreateData.IsCreated before disposing or accessing to avoid exceptions. Because NativeArray is a value-type wrapper around native memory, copying CreateAction will copy the wrapper (shallow copy) and both copies will reference the same underlying memory.

Properties

  • (none)
    This type exposes no properties.

Constructors

  • public CreateAction(int size, Allocator allocator)
    Allocates m_CreateData as a NativeArray of length size using the provided allocator. Typical allocators are Allocator.Temp, Allocator.TempJob, or Allocator.Persistent depending on the intended lifetime. Passing an invalid size (negative) or an invalid allocator will result in Unity throwing an exception.

Methods

  • public void Dispose()
    Disposes the underlying NativeArray (m_CreateData). After calling Dispose(), m_CreateData.IsCreated will be false and accessing the array will throw. To avoid exceptions on double-dispose, check m_CreateData.IsCreated before calling Dispose(). Because the struct contains a NativeArray, disposing one copy invalidates the shared native memory for all copies.

Usage Example

// Allocate for 128 entries, intended for short-to-mid lifetime (e.g. job use)
var actions = new Game.Pathfind.CreateAction(128, Allocator.TempJob);

try
{
    // Fill entries
    for (int i = 0; i < actions.m_CreateData.Length; i++)
    {
        var entry = new CreateActionData();
        // populate fields on entry...
        actions.m_CreateData[i] = entry;
    }

    // Use actions.m_CreateData in jobs or pathfinding code here
}
finally
{
    // Always free native memory
    if (actions.m_CreateData.IsCreated)
    {
        actions.Dispose();
    }
}

Additional notes: - If you pass actions into a job, prefer Allocator.TempJob and ensure the job completes before disposing. - Because CreateAction exposes a public NativeArray field, consider encapsulating access if you want stricter invariants (for example, to prevent accidental disposal from other code). - The exact layout and semantics of CreateActionData are not shown here; ensure its fields are suitable for NativeArray usage (blittable, deterministic size).