Skip to content

Game.Pathfind.DensityAction

Assembly: Assembly-CSharp (game code)
Namespace: Game.Pathfind

Type: struct

Base: System.ValueType

Summary:
Lightweight value type wrapper that holds a NativeQueue of DensityActionData used by the pathfinding/density systems. It provides initialization of the queue with a specified Unity Allocator and a Dispose method to release native memory. The struct itself does not encapsulate enqueue/dequeue logic — callers access the public NativeQueue field directly.


Fields

  • public Unity.Collections.NativeQueue<DensityActionData> m_DensityData
    Public NativeQueue that stores DensityActionData elements. The queue is created in the constructor with the supplied Allocator. Because this is a native collection, it must be disposed to avoid memory leaks.

Properties

  • (None)

Constructors

  • public DensityAction(Unity.Collections.Allocator allocator)
    Initializes the m_DensityData queue using the provided Unity Allocator (e.g., Allocator.TempJob, Allocator.Persistent). Choose the allocator according to lifetime and job usage.

Methods

  • public void Dispose()
    Disposes the underlying NativeQueue and frees native memory. Always call Dispose when the queue is no longer needed (or use a try/finally) to avoid native memory leaks.

Usage Example

using Unity.Collections;
using Game.Pathfind;

public void Example()
{
    // Create with appropriate allocator for lifetime
    var densityAction = new DensityAction(Allocator.Persistent);

    // Prepare a DensityActionData value (fields depend on that type's definition)
    var data = new DensityActionData
    {
        // initialize fields...
    };

    // Enqueue items
    densityAction.m_DensityData.Enqueue(data);

    // Dequeue / process items
    while (densityAction.m_DensityData.Count > 0)
    {
        var item = densityAction.m_DensityData.Dequeue();
        // process item...
    }

    // When finished, dispose to free native memory
    densityAction.Dispose();
}

Notes: - NativeQueue operations and lifetime are governed by Unity.Collections rules — ensure you use an appropriate Allocator and dispose on the correct thread/context. - For multithreaded/job usage, consider NativeQueue.ParallelWriter or other concurrency patterns; this struct only exposes the queue itself.