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
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 NativeArrayof 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).