Skip to content

Game.Pathfind.UpdateAction

Assembly: Assembly-CSharp
Namespace: Game.Pathfind

Type: public struct

Base: System.ValueType

Summary:
UpdateAction is a lightweight disposable container that owns a NativeArray of UpdateActionData entries. It is used to allocate and hold per-item update data for pathfinding-related work. The struct provides a constructor to allocate the NativeArray with a given size and allocator, and implements IDisposable so the underlying native memory can be released when no longer needed. Be careful to dispose instances (or their internal NativeArray) to avoid native memory leaks; choose the Allocator appropriately (Temp / TempJob / Persistent) depending on lifetime and whether the array will be used in jobs.


Fields

  • public Unity.Collections.NativeArray<UpdateActionData> m_UpdateData
    This is the owned NativeArray that holds UpdateActionData elements. It is allocated in the constructor with the given size and Allocator. Access this field directly to read/write per-item update data. Always ensure the array is properly allocated (m_UpdateData.IsCreated) before accessing, and dispose it when finished to free native memory.

Properties

  • None.
    This struct exposes its NativeArray field directly and does not define C# properties.

Constructors

  • public UpdateAction(int size, Unity.Collections.Allocator allocator)
    Allocates a new NativeArray of the given size using the supplied Allocator. The allocator controls lifetime and where the memory is allocated (e.g., Allocator.Temp, Allocator.TempJob, Allocator.Persistent). The caller is responsible for calling Dispose (or otherwise freeing the array) when the data is no longer needed.

Usage notes: - Use Allocator.Temp for very short-lived allocations within a single frame. - Use Allocator.TempJob if the array will be used by Jobs and disposed within a short time. - Use Allocator.Persistent for longer-lived storage but remember to Dispose manually.

Methods

  • public void Dispose()
    Disposes the internal NativeArray by calling m_UpdateData.Dispose(). This releases the native memory backing the array. Before calling Dispose, you can check m_UpdateData.IsCreated to verify the array was allocated. After Dispose, the NativeArray is no longer valid and must not be accessed.

Threading/note: Disposal should be performed on an appropriate thread depending on the Allocator and usage (e.g., do not dispose a NativeArray still in use by a running job).

Usage Example

// Allocate, use, and dispose explicitly
var updateAction = new UpdateAction(128, Unity.Collections.Allocator.Persistent);
try
{
    // Populate entries (UpdateActionData is a user-defined/engine struct)
    for (int i = 0; i < updateAction.m_UpdateData.Length; i++)
    {
        updateAction.m_UpdateData[i] = new UpdateActionData(/* ... */);
    }

    // Use updateAction.m_UpdateData in pathfinding work, jobs, etc.
}
finally
{
    // Ensure native memory is freed
    if (updateAction.m_UpdateData.IsCreated)
        updateAction.Dispose();
}

// Or use C# using pattern (struct implements IDisposable)
using (var action = new UpdateAction(64, Unity.Collections.Allocator.TempJob))
{
    // work with action.m_UpdateData
    // action.Dispose() will be called automatically at end of using block
}