Skip to content

Game.RouteToolSystem

Assembly: Game (game executable)
Namespace: Game.Tools

Type: class

Base: ToolBaseSystem

Summary:
RouteToolSystem is the in-game tool system that drives creation, modification and removal of routes (transport lines and work routes) in Cities: Skylines 2. It handles user input, raycasting, snapping to existing waypoints/lanes/stops, creating temporary preview routes, generating creation definitions for the UI, and applying or cancelling operations. It exposes the currently selected RoutePrefab and tool state and coordinates burst jobs for snapping and definition creation.


Nested types

  • public enum State
    Represents the tool state: Default, Create, Modify, Remove.

  • public enum Tooltip
    Tooltip identifiers used by the tool to show context-sensitive UX hints (CreateRoute, ModifyWaypoint, AddWaypoint, MergeWaypoints, DeleteRoute, etc).

  • private struct SnapJob : IJob (BurstCompile)
    Job responsible for snapping control points to nearest valid locations (waypoints, stops, lanes, subobjects) according to prefab RouteData, transport type and current State.

  • private struct CreateDefinitionsJob : IJob (BurstCompile)
    Job that builds CreationDefinition/WaypointDefinition buffers used to present visual previews / temporary objects and determine the current tooltip/color state.

  • private struct TypeHandle
    Internal container of ComponentTypeHandle / ComponentLookup / BufferLookup instances used to access ECS component data inside jobs and the system.

Fields

  • private AudioManager m_AudioManager
    Reference to the AudioManager system used to play UI sounds for start/complete/build/remove actions.

  • private EntityQuery m_DefinitionQuery
    Query used to find and destroy previously created temporary definition entities.

  • private EntityQuery m_TempRouteQuery
    Query to find temporary route entities (Route + Temp) that the tool uses while building/modifying routes.

  • private EntityQuery m_EventQuery
    Query for PathUpdated / event components used to detect relevant pathfinding updates.

  • private EntityQuery m_SoundQuery
    Query to read tool sound settings (ToolUXSoundSettingsData).

  • private IProxyAction m_AddWaypoint
    Input action proxy for adding a waypoint.

  • private IProxyAction m_InsertWaypoint
    Input action proxy for inserting a waypoint.

  • private IProxyAction m_MoveWaypoint
    Input action proxy for moving a waypoint.

  • private IProxyAction m_MergeWaypoint
    Input action proxy for merging a waypoint.

  • private IProxyAction m_RemoveWaypoint
    Input action proxy for removing a waypoint.

  • private IProxyAction m_UndoWaypoint
    Input action proxy for undoing the last waypoint.

  • private IProxyAction m_CreateRoute
    Input action proxy for creating a route.

  • private IProxyAction m_CompleteRoute
    Input action proxy for completing a route.

  • private IProxyAction m_DeleteRoute
    Input action proxy for deleting a route.

  • private IProxyAction m_DiscardInsertWaypoint
    Input action proxy for discarding an inserted waypoint.

  • private IProxyAction m_DiscardMoveWaypoint
    Input action proxy for discarding a move waypoint operation.

  • private IProxyAction m_DiscardMergeWaypoint
    Input action proxy for discarding a merge waypoint operation.

  • private bool m_ApplyBlocked
    Flag used to temporarily block apply actions (e.g., during certain transitions).

  • private ControlPoint m_LastRaycastPoint
    Last raycast result saved for change detection.

  • private NativeList<ControlPoint> m_ControlPoints
    The list of control points currently manipulated by the tool (persistent native list).

  • private NativeValue<Tooltip> m_Tooltip
    Current tooltip value (native container used by jobs/producer).

  • private State m_State
    Current tool state (Default/Create/Modify/Remove).

  • private bool m_ControlPointsMoved
    Tracks whether control points have been moved since entering a mode.

  • private bool m_ForceApply
    Force apply flag used to trigger an Apply on the next update.

  • private bool m_ForceCancel
    Force cancel flag used to trigger a Cancel on the next update.

  • private bool m_CanApplyModify
    When modifying a route, indicates whether the modification can be applied.

  • private ControlPoint m_MoveStartPosition
    The original control point used when starting a modify/remove operation (start waypoint/segment reference).

  • private ToolOutputBarrier m_ToolOutputBarrier
    Command buffer barrier used to create/destroy temporary definition entities safely.

  • private RoutePrefab m_SelectedPrefab
    Currently selected route prefab (transport line or work route).

  • private TypeHandle __TypeHandle
    Internal cached handles to components used for jobs / read access.

Properties

  • public override string toolID { get; }
    Returns "Route Tool". Identifier for this tool.

  • public RoutePrefab prefab { get; set; }
    The currently selected RoutePrefab. Setting this forces an update, updates color, serviceUpgrade availability and triggers EventPrefabChanged on the tool system.

  • public State state { get; }
    Current tool State.

  • public ControlPoint moveStartPosition { get; }
    The control point that was used to start a modify/remove operation (read-only).

  • public Tooltip tooltip { get; }
    Current tooltip value (contextual UX hint).

  • public bool underground { get; set; }
    Whether the tool is currently operating underground (affects raycast collisionMask).

  • public bool serviceUpgrade { get; private set; }
    Whether the selected prefab supports service upgrades (set when prefab is changed).

  • private protected override IEnumerable<IProxyAction> toolActions { get; }
    Enumerates the tool's action proxies for integration with input/UI. Includes add/insert/move/merge/remove/undo/create/complete/delete/discard actions.

Constructors

  • public RouteToolSystem()
    Default constructor. (Preserved attribute applied in source.)

Methods

  • [Preserve] protected override void OnCreate()
    Initializes system: obtains references to other systems (ToolOutputBarrier, AudioManager), prepares EntityQueries, retrieves input actions from InputManager, allocates NativeList and NativeValue containers. Call base.OnCreate() then set up fields.

  • [Preserve] protected override void OnDestroy()
    Disposes native containers (m_ControlPoints, m_Tooltip) and calls base.OnDestroy().

  • [Preserve] protected override void OnStartRunning()
    Resets tool state when the system starts running: clears control points, sets state to Default, clears tool flags like m_ForceApply, m_ApplyBlocked, and sets required tool constraints to defaults.

  • private protected override void UpdateActions()
    Called each update to refresh proxy action states (apply/secondary/cancel). Uses ProxyAction.DeferStateUpdating() while updating.

  • private void UpdateApplyAction()
    Updates base.applyAction.enabled and base.applyActionOverride depending on current state, selected prefab, and control points; decides context-sensitive primary action (Add/Insert/Move/Merge/Complete/Create).

  • private void UpdateSecondaryApplyAction()
    Updates base.secondaryApplyAction and override depending on state (e.g., Undo waypoint, Remove waypoint, Delete route).

  • private void UpdateCancelAction()
    Updates base.cancelAction and override for cancelling in modify mode (discard move/merge/insert).

  • public NativeList<ControlPoint> GetControlPoints(out JobHandle dependencies)
    Returns the current m_ControlPoints and writes the system's base.Dependency to dependencies so callers can chain jobs.

  • public override PrefabBase GetPrefab()
    Returns the currently selected prefab (RoutePrefab).

  • public override bool TrySetPrefab(PrefabBase prefab)
    Attempts to set the tool's prefab; returns true when the provided prefab is a RoutePrefab and was accepted.

  • public override void SetUnderground(bool underground)
    Sets underground property.

  • public override void ElevationUp()
    Sets underground = false.

  • public override void ElevationDown()
    Sets underground = true.

  • public override void ElevationScroll()
    Toggles underground.

  • public override void InitializeRaycast()
    Configures the internal raycast system (m_ToolRaycastSystem) according to the selected prefab's RouteData and transport type: sets TypeMask, Layer masks, collision masks, routeType and flags like build/passenger/cargo. Takes into account modify/remove state and underground flag.

  • [Preserve] protected override JobHandle OnUpdate(JobHandle inputDeps)
    Main update loop. Handles user inputs (apply/secondary/cancel actions), transitions between states (Default/Create/Modify/Remove), triggers SnapControlPoints and UpdateDefinitions jobs, and schedules Apply/Cancel/Clear operations. Also handles temporary force apply/cancel and checks pathfinding completion/state.

  • protected override bool GetRaycastResult(out ControlPoint controlPoint)
    Wrapper over base raycast helpers to produce a ControlPoint from last hit entity/hit. Returns true if there is a raycast hit.

  • protected override bool GetRaycastResult(out ControlPoint controlPoint, out bool forceUpdate)
    Overload that also reports whether the raycast result forces a UI update.

  • private JobHandle Clear(JobHandle inputDeps)
    Sets applyMode to Clear and returns inputDeps (no expensive work).

  • private JobHandle Cancel(JobHandle inputDeps, bool singleFrameOnly = false)
    Handles cancelling user actions depending on current state: transitions state machine, plays remove sound, prepares preview/temp route queries, performs raycast-based snapping and definition updates. Returns job handle chain for subsequent snapshot/definition jobs.

  • private JobHandle Apply(JobHandle inputDeps, bool singleFrameOnly = false)
    Handles applying actions depending on current state: start modify, start create, complete create, or apply modification/remove. Handles playing appropriate UI sounds, validating pathfinding completion, toggling applyMode to Apply or Clear, and scheduling snapshot/definition updates.

  • private bool GetPathfindCompleted()
    Checks whether temporary route pathfind targets are ready by inspecting PathTargets components on temporary route segments; used to decide whether a built route is complete.

  • private bool CheckPathUpdates()
    Returns true if any PathUpdated events in the world reference a Temp entity owned by this tool, indicating path updates that may require re-evaluation.

  • private JobHandle Update(JobHandle inputDeps, bool fullUpdate)
    Updates internal control points based on current raycast results, decides when to SnapControlPoints and call UpdateDefinitions, handles no-hit fallback behavior for various states, and sets base.applyMode appropriately.

  • private Entity GetUpgradable(Entity entity)
    Returns the "upgradable" entity (attached parent if entity has Attached), used to detect service upgrade owners.

  • private JobHandle SnapControlPoints(JobHandle inputDeps, Entity applyTempRoute)
    Schedules the SnapJob (Burst) to snap the m_ControlPoints NativeList. The job is provided with many ComponentLookup/BufferLookup handles and uses m_Prefab entity + state to snap appropriately. Returns the scheduled JobHandle.

  • private JobHandle UpdateDefinitions(JobHandle inputDeps, Entity applyTempRoute)
    Destroys previous temporary definition entities and, if a prefab is selected, schedules CreateDefinitionsJob to create new preview definitions (CreationDefinition/WaypointDefinition buffers). Adds job handles to m_ToolOutputBarrier for safe command buffer application. Returns combined JobHandle.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Internal helper used by compiler-generated OnCreateForCompiler to initialize queries. No logic in source (placeholder).

  • protected override void OnCreateForCompiler()
    Compiler helper which assigns queries and type handles (calls __AssignQueries and __TypeHandle.__AssignHandles).

Usage Example

// Acquire the system and configure it (typical usage from a mod initialization point)
var world = World.DefaultGameObjectInjectionWorld;
var routeTool = world.GetOrCreateSystemManaged<Game.Tools.RouteToolSystem>();

// Set the RoutePrefab (RoutePrefab must be obtained from the game's PrefabSystem)
RoutePrefab myRoutePrefab = /* obtain RoutePrefab via PrefabSystem or editor UI */;
routeTool.prefab = myRoutePrefab;

// Optionally toggle underground mode
routeTool.underground = true;

// The tool then runs as part of the game update loop; you can query its state:
var state = routeTool.state;
var tooltip = routeTool.tooltip;

Notes / Tips: - The tool heavily relies on ECS component lookups and scheduled Burst jobs — be careful when calling into it from jobs or other systems; use GetControlPoints(out JobHandle) to capture dependencies. - Changes to prefab property automatically mark the tool for update and fire an EventPrefabChanged notification on the tool system. - The tool distinguishes TransportLine routes vs WorkRoute and adjusts raycast/lane/stop validation accordingly.