Skip to content

Game.CommonPathfindSetup

Assembly: Game
Namespace: Game.Simulation

Type: struct

Base: System.ValueType

Summary:
CommonPathfindSetup is a utility struct used by the PathfindSetupSystem to prepare pathfinding targets for entities. It contains component lookups and references to the Net search system and schedules several Burst-compiled IJobParallelFor jobs to collect candidate path targets for different scenarios: current location, accident sites, and safety scanning. The jobs use a NativeQuadTree (net search tree) and multiple ComponentLookup/BufferLookup types to find and enqueue PathTarget entries into PathfindSetup buffers. This is designed to run in multithreaded Burst jobs and integrates with the SearchSystem's net search tree reader tracking.


Fields

  • private Game.Net.SearchSystem m_NetSearchSystem
    Reference to the game's Net SearchSystem used to obtain the NativeQuadTree (net search tree) for querying nearby network edges.

  • private ComponentLookup<PathOwner> m_PathOwnerData
    ComponentLookup (read-only) for PathOwner components — used to inspect existing path elements for entities.

  • private ComponentLookup<Vehicle> m_VehicleData
    ComponentLookup (read-only) for Vehicle components — used to detect vehicles and adjust search behavior for pedestrian methods.

  • private ComponentLookup<Composition> m_CompositionData
    ComponentLookup (read-only) for Composition components — used to access composition for edges/entities during iteration.

  • private ComponentLookup<NetCompositionData> m_NetCompositionData
    ComponentLookup (read-only) for NetCompositionData — used to evaluate lane availability, width, and composition state.

  • private ComponentLookup<Creature> m_CreatureData
    ComponentLookup (read-only) for Creature components — used by accident setup logic to filter targets.

  • private ComponentLookup<AccidentSite> m_AccidentSiteData
    ComponentLookup (read-only) for AccidentSite components — used to detect and process accident/event sites.

  • private BufferLookup<PathElement> m_PathElements
    BufferLookup (read-only) for PathElement buffers — used to read an entity's path elements if present.

  • private BufferLookup<Game.Areas.SubArea> m_SubAreas
    BufferLookup (read-only) for SubArea buffers — used to add area targets when area nodes are present.

  • private BufferLookup<TargetElement> m_TargetElements
    BufferLookup (read-only) for TargetElement buffers — used primarily by accident handling to enumerate event targets.

Properties

  • None (no public properties exposed).
    This struct exposes functionality via its constructor and public scheduling methods; internal component lookups are stored as private fields and updated before scheduling jobs.

Constructors

  • public CommonPathfindSetup(PathfindSetupSystem system)
    Initializes the CommonPathfindSetup instance: obtains the SearchSystem from the world, and creates ComponentLookup and BufferLookup objects (read-only) for the various components and buffers used by the setup jobs. These lookups are later updated (their internal safety/version state) before scheduling jobs.

Methods

  • public JobHandle SetupCurrentLocation(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
    Updates relevant ComponentLookup/BufferLookup objects and schedules the Burst-compiled SetupCurrentLocationJob (IJobParallelFor) to collect path targets based on each seeker/entity's current location. The job queries the net search tree (as a read-only reader), enqueues PathTarget entries into the seeker buffer (including special handling for flying lanes, building/transport ownership, existing path end elements, pedestrian/vehicle rules, and sub-area targets), and returns the scheduled JobHandle. The method also adds the returned job as a reader to the SearchSystem net search tree.

  • public JobHandle SetupAccidentLocation(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
    Updates relevant ComponentLookup/BufferLookup objects and schedules the Burst-compiled SetupAccidentLocationJob (IJobParallelFor) to process AccidentSite entities. The job inspects the accident's event target elements, optionally filters targets by creature/vehicle presence for traffic accidents, finds nearby edges and flying lanes, and adds area targets. Returns a JobHandle and registers it as a net search tree reader.

  • public JobHandle SetupSafety(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
    Updates composition lookups and schedules the Burst-compiled SetupSafetyJob (IJobParallelFor). This job searches a fixed radius (100 units) around the entity (considering building/transport context) and adds edge/lane targets for safety routing (e.g., building road edges). Returns a JobHandle and registers it as a net search tree reader.

Additional internal/nested types (summaries): - SetupCurrentLocationJob (private, [BurstCompile], IJobParallelFor)
Finds targets around an entity's current position, handles path end elements, different PathMethod types (Road, Pedestrian, Flying), uses composition and net composition to determine suitable edges, and enqueues PathTarget entries into the pathfind setup buffer.

  • SetupAccidentLocationJob (private, [BurstCompile], IJobParallelFor)
    Processes AccidentSite entities and their event target lists, applies filtering for traffic accidents, queries flying lanes and nearby edges, and adds area targets where appropriate.

  • SetupSafetyJob (private, [BurstCompile], IJobParallelFor)
    Performs a safety-oriented scan within 100 units, preferring building road-edge lanes and nearby edges suitable for pedestrian/road methods.

  • TargetIterator (public struct implementing INativeQuadTreeIterator and IUnsafeQuadTreeIterator)
    Iterator used when iterating the NativeQuadTree. For each candidate edge entity it:

  • checks composition and net composition state for lane availability matching requested PathMethods (road/pedestrian),
  • computes the distance from the seeker position to the edge curve minus half the edge width,
  • if within the search radius, uses the seeker's Random and PathfindTargetSeeker.AddEdgeTargets to enqueue edge lane targets.

Usage Example

// Example: scheduling the current-location setup for pathfinding.
// 'system' is a PathfindSetupSystem instance.
// 'setupData' is a PathfindSetupSystem.SetupData containing seekers to process.
// 'deps' is any JobHandle dependencies you need to wait on.

var commonSetup = new CommonPathfindSetup(system);

// Schedule the current-location scanning jobs. The method returns a JobHandle you should use
// to chain further work or complete before reading produced buffers.
JobHandle handle = commonSetup.SetupCurrentLocation(system, setupData, deps);

// Optionally schedule accident/safety setups similarly:
JobHandle accidentHandle = commonSetup.SetupAccidentLocation(system, setupData, handle);
JobHandle safetyHandle = commonSetup.SetupSafety(system, setupData, JobHandle.CombineDependencies(handle, accidentHandle));

// Ensure completion before consuming results (or pass handles into next systems/jobs).
safetyHandle.Complete();

Notes: - All setup jobs are Burst-compiled and scheduled as IJobParallelFor; component/lookups are updated every call to ensure correct safety/versioning. - The net search tree is requested as a read-only resource and the SearchSystem is notified of each job that reads it to coordinate access.