Skip to content

Game.Net.ConnectionWarningSystem

Assembly: Assembly-CSharp (Game)
Namespace: Game.Net

Type: class

Base: GameSystemBase

Summary:
ConnectionWarningSystem is a Unity ECS/GameSystemBase that scans network nodes, edges, buildings and related sub-objects to create and update connection-related UI notifications (icons) for Cities: Skylines 2. It uses Burst jobs, Unity's Job System and several Native collections/quadtrees to:

  • Collect owners (nodes, buildings, subnets, etc.) that need checking (CollectOwnersJob / CollectOwnersJob2).
  • Produce connection and pathfinding-related warnings such as:
  • Network connection missing icons (power, water, sewage, resources),
  • Dead-end notifications for lanes,
  • Track/road/ship/bridge connection notifications,
  • Pathfinding "island" (no path) warnings for buildings and spawn/takeoff locations.
  • Interact with IconCommandSystem to add/remove icons and with Search/Area systems to read spatial data.
  • Consider editor mode, map-tile updates and "new game" startup behavior.

This system is heavily optimized for multithreaded execution (IJob / IJobParallelForDefer) and relies on many ComponentLookup/BufferLookup handles and configuration singletons (WaterPipeParameterData, ElectricityParameterData, TrafficConfigurationData).


Fields

  • private ToolSystem m_ToolSystem
    Reference to the ToolSystem (used to check editor/action modes and other tool-related state).

  • private IconCommandSystem m_IconCommandSystem
    The IconCommandSystem used to create command buffers for adding/removing notification icons.

  • private Game.Areas.SearchSystem m_AreaSearchSystem
    Search system for area queries (used when checking whether something is on a native map tile, etc.).

  • private Game.Areas.UpdateCollectSystem m_AreaUpdateCollectSystem
    Tracks updated map tile bounds and whether map tiles were updated this frame.

  • private SearchSystem m_NetSearchSystem
    Network search tree provider used by CollectOwnersJob2.

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    Object search tree provider used by CollectOwnersJob2.

  • private EntityQuery m_UpdateQuery
    Query describing entities that trigger regular updates (Updated + Node/ServiceUpgrade/Spawn/TakeoffLocation, excluding Temp).

  • private EntityQuery m_NewGameQuery
    Query used on NewGame (to treat initial placement as changed).

  • private EntityQuery m_WaterConfigQuery
    Query for retrieving WaterPipeParameterData singleton.

  • private EntityQuery m_ElectricityConfigQuery
    Query for retrieving ElectricityParameterData singleton.

  • private EntityQuery m_TrafficConfigQuery
    Query for retrieving TrafficConfigurationData singleton.

  • private bool m_IsNewGame
    Flag set during game load if the purpose is a new game (used to choose m_NewGameQuery vs m_UpdateQuery).

  • private TypeHandle __TypeHandle
    Internal struct capturing Entity/Component type handles and ComponentLookup/BufferLookup instances used by jobs.

  • (Nested/private) CollectOwnersJob, CollectOwnersJob2, CheckOwnersJob and supporting nested types such as PathfindElement, BufferElement, MapTileIterator, NodeIterator, BuildingIterator, IconItem, and various helper structs.
    These are the Burst-compiled jobs and data types that perform the heavy lifting of scanning and computing warnings.


Properties

  • None (the system does not declare public properties).

Constructors

  • public ConnectionWarningSystem()
    Default constructor. System initialization logic is in OnCreate override.

Methods

  • protected override void OnCreate()
    Initializes references to other systems, sets up EntityQueries (m_UpdateQuery, m_NewGameQuery, config queries). Use this to understand which systems this system depends on.

  • protected override void OnGameLoaded(Context serializationContext)
    Called when the game is loaded. Sets m_IsNewGame based on serializationContext.purpose == Purpose.NewGame.

  • protected override void OnUpdate()
    Main update method. It:

  • Chooses the appropriate entity query (new game vs update),
  • Builds a NativeList of owners that need checking,
  • Schedules CollectOwnersJob and/or CollectOwnersJob2 depending on what changed (entities updated and/or map tiles updated),
  • Schedules the CheckOwnersJob (IJobParallelForDefer) to produce icons and notifications,
  • Adds readers/writers for search trees and command buffers and sets base.Dependency to the scheduled job handle.

The method shows the interplay between chunk-based collection, spatial quadtree iteration, deferred job arrays and IconCommandBuffer usage.

  • private T GetConfigData<T>(EntityQuery query) where T : unmanaged, IComponentData
    Helper to fetch singleton configuration component from a query, returning default(T) if the query is empty. Used to read WaterPipeParameterData, ElectricityParameterData and TrafficConfigurationData safely.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper for assigning/initializing queries (used internally).

  • protected override void OnCreateForCompiler()
    Compiler-time initialization entry; assigns queries and component type handles via __TypeHandle.__AssignHandles.

  • (Many private helper methods inside CheckOwnersJob) Examples:

  • UpdatePathfindIslandWarnings / ClearPathfindIslandWarnings
  • UpdatePathfindWarnings / CheckConnectedElements
  • AddPathfindElements / AddPathfindElements overloads for lanes/subnets/subobjects
  • UpdateSubnetConnectionWarnings / UpdateNodeConnectionWarnings
  • FillNodeConnections, CheckNodeConnections, AddNodeConnection
  • FindEdgeConnections, FindSecondaryConnections
  • UpdateConnectionWarnings (per-layer and per-subnet)
  • UpdateConnectionWarning (calls IconCommandBuffer.Add/Remove)

These methods implement the core logic for detecting missing connections and placing/removing the proper notification icons (using icons from TrafficConfigurationData, Water/Electric parameters, ResourceConnectionData etc.), as well as lane-level dead-end/track-connection notifications.

  • (Nested job Execute implementations)
  • CollectOwnersJob.Execute(): collects unique owner entities from changed archetype chunks and RoadConnectionUpdated events.
  • CollectOwnersJob2.Execute(): spatially queries net/object quadtrees for updated map tiles and collects owner entities overlapping updated map tiles.
  • CheckOwnersJob.Execute(int index): performs the per-owner analysis and issues IconCommandBuffer operations.

Notes on threads and memory: - The system uses Native collections (NativeList, NativeParallelHashSet, NativeParallelMultiHashMap, NativeHashMap) allocated with Allocator.Temp or TempJob and disposed inside jobs or after scheduling. Many of the nested jobs are Burst-compiled for performance. - The IconCommandBuffer created via m_IconCommandSystem.CreateCommandBuffer() is used to batch icon add/remove operations safely across jobs.


Usage Example

// Typical usage for modders: retrieve the existing system instance to inspect or interact with it.
// Note: ConnectionWarningSystem has no public API to trigger checks directly; it runs as part of the ECS update.
// You can get the system to read config queries or check dependencies:

var world = Unity.Entities.World.DefaultGameObjectInjectionWorld;
var connWarnSystem = world.GetExistingSystemManaged<Game.Net.ConnectionWarningSystem>();

// You can also read the traffic/water/electricity config singletons used by the system:
var trafficConfigQuery = connWarnSystem != null
    ? connWarnSystem.GetType() // (private internals — direct config access normally not public)
    : null;

// Most modders will not call internals of the system. If you need to adjust behavior, consider:
// - creating a system that runs Before/After ConnectionWarningSystem via [UpdateInGroup]/[UpdateBefore]/[UpdateAfter]
// - using IconCommandSystem to add/remove custom icons
// - providing custom PrefabRef/ResourceConnectionData changes or replacing config singletons.

{{ Additional information for modders: - This system is central to showing visual feedback for missing connections (power/water/sewage/resources) and for pathfind-based island/warning icons. If you need to suppress or extend notifications, prefer using IconCommandSystem or schedule a system that runs after ConnectionWarningSystem to tweak icons (the system exposes no public removal hooks beyond IconCommandSystem). - If you modify network prefab data (NetData, LocalConnectData, CarLaneData, TrackLaneData, ResourceConnectionData, etc.), ConnectionWarningSystem will pick up changes via its component lookups the next frame. - The implementation assumes many internal components/types from the game's ECS (SubNet, SubLane, ConnectedEdge, ConnectedNode, PathNode wrappers, etc.). Inspect those types when extending or diagnosing notification behavior. - Because this system is optimized for multithreading, avoid accessing or modifying the same components from custom systems without proper synchronization (use AddSearchTreeReader/AddCommandBufferWriter where appropriate or schedule dependencies). }}