Skip to content

Game.FindSchoolSystem

Assembly: Game
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
FindSchoolSystem is a simulation system responsible for locating schools for citizens flagged as SchoolSeeker, scheduling pathfinding requests to those schools, and processing the pathfinding results to enroll citizens as students. It runs in two main phases: - FindSchoolJob (IJobChunk) — iterates SchoolSeeker entities that do not yet have PathInformation, gathers required context (owner/citizen, household, district, vehicle methods, pathfinding weights), creates PathfindSetup queue items and tags the seeker entity with pending PathInformation. - StartStudyingJob (IJob) — processes seekers that already have PathInformation (path result), attempts to add the citizen to the destination school's student buffer (respecting capacity and applied upgrades), converts workers to students when necessary, fires a TriggerAction (CitizenStartedSchool), resets failed education counters, adds cooldowns when no seat found, and cleans up SchoolSeeker markers and temporary seeker entities.

The system integrates with: - PathfindSetupSystem — to enqueue pathfinding setup items. - EndFrameBarrier — to create command buffers for structural changes. - TriggerSystem — to enqueue citizen-started-school triggers. - CitySystem / SimulationSystem — to read city/time/economy state.

Update cadence: GetUpdateInterval returns 16 (system updates every 16 frames).


Fields

  • public bool debugFastFindSchool
    Flag (likely used for debugging/testing) to enable a faster find-school behavior in StartStudyingJob. Default false.

  • private PathfindSetupSystem m_PathfindSetupSystem
    Reference to the PathfindSetupSystem used to enqueue pathfinding work.

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem (used to read the simulation frame index).

  • private CitySystem m_CitySystem
    Reference to the CitySystem (used to get the city entity).

  • private EndFrameBarrier m_EndFrameBarrier
    End-of-frame barrier used to create EntityCommandBuffer(s) for structural changes produced by jobs.

  • private EntityQuery m_SchoolSeekerQuery
    Query selecting SchoolSeeker entities that do NOT yet have PathInformation (these are processed by FindSchoolJob).

  • private EntityQuery m_ResultsQuery
    Query selecting SchoolSeeker entities that DO have PathInformation (these are processed by StartStudyingJob).

  • private TriggerSystem m_TriggerSystem
    Reference to TriggerSystem used to enqueue TriggerAction events.

  • private TypeHandle __TypeHandle
    Internal container used to cache component/entity type handles and lookup handles for use inside jobs.

  • private EntityQuery __query_17488131_0
    Internal query for EconomyParameterData singleton used by StartStudyingJob.

  • private EntityQuery __query_17488131_1
    Internal query for TimeData singleton used by StartStudyingJob.


Properties

  • (No public properties exposed)
    All interaction is via system methods / fields and component state changes. The system relies on component queries and job-supplied handles.

Constructors

  • public FindSchoolSystem()
    Default constructor. The actual runtime initialization occurs in OnCreate where dependent systems and entity queries are obtained. Marked with [Preserve] for IL2CPP code stripping considerations.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns 16. Controls how frequently the system runs (every 16 simulation frames).

  • protected override void OnCreate()
    Initializes references to dependent systems (EndFrameBarrier, PathfindSetupSystem, TriggerSystem, CitySystem, SimulationSystem) and creates the two primary EntityQueries:

  • m_SchoolSeekerQuery: SchoolSeeker + Owner, excluding PathInformation and Deleted.
  • m_ResultsQuery: SchoolSeeker + Owner + PathInformation, excluding Deleted. Also registers required singletons (EconomyParameterData, TimeData) as required for updates.

  • protected override void OnUpdate()
    Main scheduling logic:

  • If m_SchoolSeekerQuery has items, schedules FindSchoolJob (IJobChunk) in parallel:
    • Collects owner/citizen/household info, determines the destination district, prepares PathfindParameters (speeds, weights, methods, flags), sets PathInformation on the seeker entity with Pending, and enqueues a SetupQueueItem into PathfindSetupSystem.
    • Uses EndFrameBarrier's parallel EntityCommandBuffer to add PathInformation and Deleted when necessary.
    • Registers PathfindSetupSystem and EndFrameBarrier dependencies.
  • If m_ResultsQuery has items, schedules StartStudyingJob (IJob) after collecting an archetype chunk list:

    • For each seeker that has PathInformation (path result processed), verifies destination is a prefab with a Student buffer and a prefab that has SchoolData.
    • Combines school stats with installed upgrades, checks capacity, and if there is room:
    • Adds the citizen to the school's student buffer.
    • Adds Game.Citizens.Student component to the citizen with school entity, last commute time, and education level.
    • If the citizen was a Worker, removes them from the employee buffer of their workplace and removes the Worker component.
    • Enqueues TriggerAction(CitizenStartedSchool).
    • Resets failed education count on the citizen.
    • Removes any SchoolSeekerCooldown component on the citizen.
    • If no seat is found, adds SchoolSeekerCooldown with current simulation frame.
    • Always removes HasSchoolSeeker component and deletes the seeker entity.
    • Uses EndFrameBarrier EntityCommandBuffer and TriggerSystem action buffer and sets appropriate job dependencies.
  • private void __AssignQueries(ref SystemState state)
    Internal helper used by OnCreateForCompiler to build the internal queries for EconomyParameterData and TimeData singletons.

  • protected override void OnCreateForCompiler()
    Internal initialization hook used when compiling to ensure queries and type handles are assigned for jobs.

  • Nested: FindSchoolJob (IJobChunk) — Execute(...)
    Job that runs over seeker archetype chunks and:

  • Gets arrays for entity, Owner and SchoolSeeker components.
  • For each seeker:

    • Validates owner exists as a Citizen; if missing, marks seeker entity as Deleted.
    • Finds household and property (renter) to determine origin/district and ensure household membership.
    • Creates PathInformation on the seeker entity with PathFlags.Pending.
    • Builds PathfindParameters (max speed, walk speed, weights via CitizenUtils.GetPathfindWeights, pedestrian + public transport day methods, max cost, flags).
    • Prepares SetupQueueTarget origin (CurrentLocation, Pedestrian) and destination (SchoolSeekerTo, Pedestrian, level and district entity if found).
    • If citizen is not a child, updates vehicle methods using PathUtils.UpdateOwnedVehicleMethods.
    • Enqueues a SetupQueueItem to PathfindSetupSystem queue (as ParallelWriter).
  • Nested: StartStudyingJob (IJob) — Execute()
    Consumes the chunk list for results and:

  • Iterates chunks and per-entity checks PathInformation state; skips pending paths.
  • Verifies destination prefab and student buffer; reads SchoolData (applies installed upgrades if present) and checks capacity.
  • Adds citizen as Game.Buildings.Student and adds Game.Citizens.Student component to the citizen with commute/destination/level.
  • If citizen had Worker component, removes them from their workplace's Employee buffer, removes Worker component.
  • Enqueues TriggerAction for CitizenStartedSchool, resets citizen's failed education count, removes SchoolSeekerCooldown if enrollment succeeded.
  • If enrollment failed, adds SchoolSeekerCooldown with current simulation frame.
  • Removes HasSchoolSeeker component and deletes the seeker entity in all cases.

Notes for modders: - This system performs structural changes via EndFrameBarrier's command buffers; jobs are scheduled and dependencies are tracked with the barrier and PathfindSetupSystem. - Add/Remove/Modify components are done through EntityCommandBuffer (parallel or non-parallel depending on job). - The system expects several component types and buffers to exist on relevant entities: Owner, Citizen, HouseholdMember, PropertyRenter, PrefabRef, SchoolData, InstalledUpgrade, Student buffers, Worker, Employee buffers, PathInformation, HasSchoolSeeker, SchoolSeekerCooldown, etc. - Capacity logic respects SchoolData.m_StudentCapacity and applied InstalledUpgrade stats (UpgradeUtils.CombineStats). - TriggerAction(CitizenStartedSchool) is enqueued when enrollment occurs.


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Accessing the FindSchoolSystem (e.g. from another system or initialization code)
    var findSchoolSystem = World.GetOrCreateSystemManaged<Game.Simulation.FindSchoolSystem>();
    // Enable debug fast-find if you want faster test behavior (used inside StartStudyingJob)
    findSchoolSystem.debugFastFindSchool = true;
}

This example shows how to obtain and modify the FindSchoolSystem instance. Typical mod interactions would instead add or modify components (SchoolSeeker, HasSchoolSeeker, PrefabRef/SchoolData on buildings) to influence how the system selects and assigns students.