Skip to content

Game.Pathfind.ModificationJobs

Assembly:
Assembly-CSharp

Namespace:
Game.Pathfind

Type:
static class ModificationJobs

Base:
System.Object

Summary:
Contains a set of Burst-compiled IJob implementations and a small interface used to perform batched modifications to the pathfinding data (NativePathfindData) used by the game's pathfinder. Each nested job is responsible for a specific type of modification (create, update, delete edges, and set density/time/flow). Jobs expose a SetPathfindData method (through IPathfindModificationJob) that must be used to provide the NativePathfindData instance the job will modify before scheduling. Jobs use Native containers and queues contained in action types (CreateAction, UpdateAction, DeleteAction, DensityAction, TimeAction, FlowAction) to iterate and apply changes.


Fields

  • public CreateAction m_Action (in CreateEdgesJob)
    CreateEdgesJob holds a ReadOnly CreateAction which contains the data required to create edges (m_CreateData). The job reads that action and creates one or two edges per entry (primary and optional secondary).

  • public NativePathfindData m_PathfindData (in each job)
    All modification jobs store a NativePathfindData instance which they modify. This field is assigned via SetPathfindData before scheduling.

  • public UpdateAction m_Action (in UpdateEdgesJob)
    Holds update descriptors (m_UpdateData) used to locate and update existing edges.

  • public DeleteAction m_Action (in DeleteEdgesJob)
    Contains delete descriptors (m_DeleteData) used to remove edges and their secondary counterparts.

  • public DensityAction m_Action (in SetDensityJob)
    Contains a NativeQueue describing density values to write to edges.

  • public TimeAction m_Action (in SetTimeJob)
    Contains a NativeQueue describing travel time and direction flags for primary and/or secondary edges.

  • public FlowAction m_Action (in SetFlowJob)
    Contains a NativeQueue describing flow offsets to write to edges.

(Notes: fields above are per-job fields defined in the nested job structs. Many of the m_Action fields are marked [ReadOnly] in the job definitions.)

Properties

  • None on the static ModificationJobs type itself. (Jobs operate on public fields; they do not expose C# properties.)

Constructors

  • None explicitly defined for ModificationJobs (static utility container).
  • Each nested job is a value type (struct) and uses the default struct constructor when created. The NativePathfindData must be supplied via the SetPathfindData method before scheduling.

Methods

  • void SetPathfindData(NativePathfindData pathfindData) (IPathfindModificationJob)
    Implemented by each job struct. Assigns the NativePathfindData instance that the job will modify. This assignment should be performed on the thread that prepares/schedules the job (typically the main thread) before calling Schedule().

  • void Execute() (IJob — implemented by each nested job)
    Each job implements Execute() with behavior specific to its purpose:

  • CreateEdgesJob.Execute(): iterates m_Action.m_CreateData. For each CreateActionData:

    • If primary specification has methods, calls m_PathfindData.CreateEdge(...) to create the primary edge and registers it via m_PathfindData.AddEdge(owner, edgeID).
    • If a secondary specification is present, constructs PathNode instances for secondary start/middle/end, adjusts location (raises endpoints by 1 unit if relevant flags set), marks the specification with EdgeFlags.Secondary, creates the secondary edge via CreateEdge, and registers it via AddSecondaryEdge(owner, edgeID).
  • UpdateEdgesJob.Execute(): iterates m_Action.m_UpdateData. For each UpdateActionData:

    • If a primary edge exists for the owner, calls m_PathfindData.UpdateEdge(...) with updated node and specification data.
    • If a secondary edge exists, constructs secondary PathNode instances, adjusts location similarly to CreateEdgesJob, and updates the secondary edge.
  • DeleteEdgesJob.Execute(): iterates m_Action.m_DeleteData. For each DeleteActionData:

    • Attempts to RemoveEdge(owner, out edgeID) and, if successful, calls DestroyEdge(edgeID).
    • Attempts to RemoveSecondaryEdge(owner, out edgeID) and DestroyEdge if found.
  • SetDensityJob.Execute(): enumerates the m_Action.m_DensityData queue and for each DensityActionData:

    • If a primary edge exists for the owner, writes the density value via m_PathfindData.SetDensity(edgeID) = density.
    • If a secondary edge exists, writes the same density.
  • SetTimeJob.Execute(): enumerates the m_Action.m_TimeData queue and for each TimeActionData:

    • If TimeActionFlags.SetPrimary is set and primary edge exists: sets travel time (costs.m_Value.x) and updates allowed directions via SetEdgeDirections based on flags.
    • If TimeActionFlags.SetSecondary is set and secondary edge exists: sets travel time and computes PathNode start/end according to edge flags and sets directions.
  • SetFlowJob.Execute(): enumerates m_Action.m_FlowData and for each FlowActionData:

    • If primary/secondary edges exist, sets the flow offset via m_PathfindData.SetFlowOffset(edgeID) = m_FlowOffset.

Additional notes on methods: - All jobs are decorated with [BurstCompile], meaning they will be compiled with Burst when scheduled under supported conditions. - Jobs use Native containers and should respect Unity's safety rules: ensure containers live long enough and are accessible in the scheduled context.

Usage Example

Example of preparing and scheduling a CreateEdgesJob (same pattern applies to other modification jobs):

// Prepare the action (CreateAction) on the main thread.
// Assume createAction is already populated and nativePathfindData is obtained.
var createJob = new Game.Pathfind.ModificationJobs.CreateEdgesJob
{
    m_Action = createAction // ReadOnly field; contains m_CreateData array
};

// Provide the NativePathfindData to the job before scheduling.
createJob.SetPathfindData(nativePathfindData);

// Schedule and complete immediately (for illustration). In practice, keep JobHandle to chain dependencies.
Unity.Jobs.JobHandle handle = createJob.Schedule();
handle.Complete();

Practical tips: - Call SetPathfindData(...) on the job instance before Schedule(). - When scheduling multiple modification jobs, use JobHandle dependencies to ensure ordering (e.g., schedule CreateEdgesJob, capture its JobHandle, then schedule UpdateEdgesJob with that handle as dependency). - Complete the returned JobHandle or chain it into other jobs that depend on the modifications. - Ensure the underlying Native containers referenced by action objects remain valid for the duration of the job. - Because of Burst and job constraints, avoid using managed objects in job fields; use the provided Native containers and simple blittable structs (as defined by the game's action types).