Skip to content

Game.Pathfind.TimeAction

Assembly: Assembly-CSharp.dll
Namespace: Game.Pathfind

Type: struct

Base: implements System.IDisposable

Summary:
TimeAction is a small value-type wrapper around a Unity.Collections.NativeQueue of TimeActionData. It provides a simple lifecycle for allocating and disposing the native queue used to store time-related/pathfinding actions or events. The struct itself does not expose enqueue/dequeue helpers — it only owns the underlying NativeQueue instance and is responsible for its allocation and cleanup. Use appropriate Unity Allocator types (e.g., Allocator.Persistent or Allocator.TempJob) depending on lifetime and context.


Fields

  • public NativeQueue<TimeActionData> m_TimeData
    Holds the native queue of TimeActionData elements. This is a Unity native container and must be disposed when no longer needed to avoid native memory leaks. Because this is the non-concurrent queue type, it is not directly thread-safe for parallel writers; if you need to use it from jobs in parallel, obtain and use a Concurrent writer (NativeQueue.ParallelWriter) or use a different concurrent container.

Properties

  • None. This struct exposes the queue directly as a public field.

Constructors

  • public TimeAction(Allocator allocator)
    Allocates the m_TimeData NativeQueue using the provided Unity Allocator. Choose the allocator according to the intended lifetime:
  • Allocator.Persistent — for long-lived data across frames.
  • Allocator.TempJob — for short-lived job allocations.
  • Allocator.Temp — for single-frame usage (not valid for jobs that persist beyond the frame). Always ensure Dispose is called for the chosen allocator lifetime.

Methods

  • public void Dispose()
    Disposes the underlying m_TimeData NativeQueue, freeing native memory. Call this when the queue is no longer needed. To be defensive, check m_TimeData.IsCreated before disposing to avoid exceptions if Dispose might be called multiple times or if initialization failed.

Usage Example

using Unity.Collections;
using System;

public class ExampleUsage : IDisposable
{
    private TimeAction _timeAction;

    public ExampleUsage()
    {
        // Use Persistent for a long-lived queue; change as appropriate
        _timeAction = new TimeAction(Allocator.Persistent);
    }

    public void Enqueue(TimeActionData item)
    {
        // Ensure queue was created
        if (_timeAction.m_TimeData.IsCreated)
            _timeAction.m_TimeData.Enqueue(item);
    }

    public bool TryDequeue(out TimeActionData item)
    {
        if (_timeAction.m_TimeData.IsCreated && _timeAction.m_TimeData.Count > 0)
        {
            item = _timeAction.m_TimeData.Dequeue();
            return true;
        }

        item = default;
        return false;
    }

    public void Dispose()
    {
        // Dispose the native queue when done
        if (_timeAction.m_TimeData.IsCreated)
            _timeAction.Dispose();
    }
}

Notes and recommendations: - Ensure the lifetime of the NativeQueue aligns with job scheduling if you pass it to jobs. Use Allocator.TempJob for job-scoped containers. - Consider exposing a NativeQueue<T>.ParallelWriter if you need to enqueue from multiple worker threads/jobs. - The type TimeActionData is not defined here; it should be a blittable struct suitable for use in Unity native containers.