Skip to content

Game.AreaPathfindSetup

Assembly:
Assembly-CSharp (game code / modding)

Namespace:
Game.Simulation

Type:
public struct AreaPathfindSetup

Base:
System.ValueType

Summary:
AreaPathfindSetup is a helper struct used by PathfindSetupSystem to prepare area-based pathfinding targets for vehicles and services. It encapsulates component- and buffer-lookup caches and schedules two Burst-compiled IJobParallelFor jobs:

  • SetupAreaLocationJob: enumerates area sub-objects and installed upgrades to add area targets (or fallback area targets) to the pathfinding setup queue. It uses randomness to assign costs and filters out secondary sub-objects and inactive upgrades, and it can detect cargo transport stations.
  • SetupWoodResourceJob: enumerates wood resource buffers (trees) in an entity and adds tree targets based on vehicle work type (Harvest/Collect), factoring tree state and growth into the generated costs.

The struct keeps its ComponentLookup and BufferLookup instances up-to-date and schedules jobs with the provided PathfindSetupSystem.SetupData and dependency JobHandle.


Fields

  • private ComponentLookup<Tree> m_TreeData
    Lookup cache for Tree component data (used by SetupWoodResourceJob to inspect Tree state and growth).

  • private ComponentLookup<Secondary> m_SecondaryData
    Lookup cache for Secondary marker component (used to skip certain sub-objects in SetupAreaLocationJob).

  • private ComponentLookup<CargoTransportStationData> m_CargoTransportStationData
    Lookup cache for cargo station prefab data (used to detect and prioritize cargo transport stations among installed upgrades).

  • private BufferLookup<Game.Objects.SubObject> m_SubObjects
    Buffer lookup for SubObject buffers of entities (used to enumerate sub-objects inside an area).

  • private BufferLookup<WoodResource> m_WoodResources
    Buffer lookup for WoodResource buffers (used to enumerate trees/resources linked to an entity).

  • private BufferLookup<Game.Areas.SubArea> m_SubAreas
    Buffer lookup for SubArea buffers (used to pass area geometry/subarea information when adding targets).

  • private BufferLookup<InstalledUpgrade> m_InstalledUpgrades
    Buffer lookup for InstalledUpgrade buffers (used to enumerate installed upgrades on buildings when searching upgrade variants like other cargo stations).

Note: These lookups are updated (m_*.Update(system)) before scheduling the jobs to ensure thread-safe, read-only access during job execution.

Properties

  • None. (This struct exposes no public properties; it only holds lookups and exposes two scheduling methods.)

Constructors

  • public AreaPathfindSetup(PathfindSetupSystem system)
    Initializes the lookup caches (ComponentLookup and BufferLookup) using the provided PathfindSetupSystem. Each lookup is requested in read-only mode where appropriate. This constructor prepares the struct for subsequent SetupAreaLocation / SetupWoodResource calls.

Methods

  • public JobHandle SetupAreaLocation(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
    Schedules the Burst-compiled SetupAreaLocationJob as an IJobParallelFor that iterates over the provided setupData entries. Before scheduling, the method updates the required lookups: m_SecondaryData, m_CargoTransportStationData, m_SubObjects, m_SubAreas, and m_InstalledUpgrades. The job will:
  • For entities that have area buffers, enumerate sub-objects and add area targets (skipping Secondary sub-objects).
  • If no targets were added from sub-objects, add a fallback area target with a default random cost.
  • For entities that are buildings without area buffers, inspect InstalledUpgrade buffers to find compatible cargo transport station upgrades and add those as targets (with a random cost), respecting inactive flags and work multipliers.
  • Returns a JobHandle representing the scheduled job (chained to inputDeps).

  • public JobHandle SetupWoodResource(PathfindSetupSystem system, PathfindSetupSystem.SetupData setupData, JobHandle inputDeps)
    Schedules the Burst-compiled SetupWoodResourceJob as an IJobParallelFor that iterates over setupData entries. Before scheduling, the method updates m_TreeData, m_WoodResources, and m_SubAreas. The job will:

  • For each entity with a WoodResource buffer, iterate its entries (trees), compute a cost using Random and tree state/growth influenced logic dependent on VehicleWorkType (Harvest or Collect), and add tree area targets via the target seeker.
  • Returns a JobHandle representing the scheduled job (chained to inputDeps).

Inner job types (private and Burst-compiled): - SetupAreaLocationJob : IJobParallelFor
Uses ComponentLookup and BufferLookup (ReadOnly) plus PathfindSetupSystem.SetupData to perform per-entry setup work described above. Contains Execute(int index) that reads setupData, uses random seeds, and calls targetSeeker.AddAreaTargets / FindTargets.

  • SetupWoodResourceJob : IJobParallelFor
    Uses ComponentLookup and BufferLookup / SubArea (ReadOnly) plus PathfindSetupSystem.SetupData to add tree targets. Execute(int index) inspects each tree's TreeState and growth to bias costs appropriately for harvesting vs collecting.

Thread-safety and performance notes: - Jobs are Burst-compiled and scheduled as parallel for; all lookups used inside jobs are read-only and are updated on the main thread before scheduling. - Random seeds come from targetSeeker.m_RandomSeed.GetRandom(0) and are used to generate behaviorally varied costs. - All area target additions are made through the provided targetSeeker via the m_SetupData entries — familiarize yourself with PathfindSetupSystem.SetupData and target seeker APIs when extending behavior.

Usage Example

// Example usage pattern inside PathfindSetupSystem or a similar system:
public class MyPathfindSetupSystem : SystemBase
{
    private AreaPathfindSetup m_AreaSetup;

    protected override void OnCreate()
    {
        base.OnCreate();
        m_AreaSetup = new AreaPathfindSetup(this); // construct with PathfindSetupSystem (this)
    }

    protected override void OnUpdate()
    {
        // Assume setupData is prepared earlier in this system:
        PathfindSetupSystem.SetupData setupData = PrepareSetupData();

        JobHandle deps = default;
        // Schedule the area location setup and chain dependencies
        deps = m_AreaSetup.SetupAreaLocation(this, setupData, deps);

        // Schedule wood resource setup, chained after area setup
        deps = m_AreaSetup.SetupWoodResource(this, setupData, deps);

        // Ensure jobs complete or pass deps further
        deps.Complete();
    }
}

Notes: - Replace PrepareSetupData() with the actual way PathfindSetupSystem.SetupData is obtained in your mod / system. - Keep lookups updated via the AreaPathfindSetup methods; they internally call m_*.Update(system) before scheduling.