Skip to content

Game.GenerateNodesSystem

Assembly:
{{ Not specified in source; likely the main game assembly (e.g. Game) }}

Namespace: Game.Tools

Type: class

Base: GameSystemBase

Summary:
GenerateNodesSystem is a Unity ECS system used by the game to (re)create and update "node" entities for network prefabs (roads, rails, powerlines, waterways, etc.) when the player or game logic creates or modifies net courses, edges or objects. It collects required creation/definition data, queries nearby nets and nodes using the game's net search quad-tree, merges/filters update requests, and finally creates or reuses node entities via an EntityCommandBuffer. The system uses multiple Burst-compiled jobs (FillNodeMapJob, FillOldNodesJob, CollectUpdatesJob, CreateNodesJob) for performance and interacts with TerrainSystem, SearchSystem, ToolSystem and GenerateObjectsSystem. It handles editor mode specifics, outside-connections, owner reuse, elevation and other prefab-specific behaviors.

Key responsibilities: - Find existing nodes/edges that should be regenerated or connected when a net/course is changed. - Merge duplicate or overlapping update requests (CollectUpdatesJob). - Reuse old node entities when possible (matching by prefab, owner, original entity and proximity). - Create temporary Temp components to mark created/updated nodes and add appropriate node components (LocalConnect, Owner, Upgraded, Fixed, Elevation, Orphan, Standalone, etc.). - Use a ModificationBarrier1 command buffer to apply entity changes safely after job execution.

Notable nested job/struct types (important to modders): - UpdateData, NodeKey, DefinitionData, OldNodeKey, OldNodeValue - FillOldNodesJob (IJobChunk) — fills map of existing nodes for reuse matching - FillNodeMapJob (IJobChunk) — scans creation definitions and net courses to enqueue node updates - CollectUpdatesJob (IJob) — deduplicates and merges update requests - CreateNodesJob (IJob) — performs final node creation/reuse via EntityCommandBuffer - TypeHandle (internal helper to cache ComponentTypeHandle/ComponentLookup/BufferLookup)


Fields

  • private ToolSystem m_ToolSystem
    {{ Reference to the ToolSystem; used to query editor/action mode (e.g. m_ToolSystem.actionMode.IsEditor()). }}

  • private Game.Net.SearchSystem m_SearchSystem
    {{ Used to access the game's net search quad-tree (m_NetSearchTree) for spatial queries of edges/nodes. }}

  • private TerrainSystem m_TerrainSystem
    {{ Used to get terrain height bounds/data for outside connection checks and elevation logic. }}

  • private GenerateObjectsSystem m_GenerateObjectsSystem
    {{ Used to obtain reused-owner map (owner reuse for placed nodes/objects). }}

  • private ModificationBarrier1 m_ModificationBarrier
    {{ Used to create an EntityCommandBuffer to apply structural/component changes after jobs finish. }}

  • private EntityQuery m_DefinitionQuery
    {{ EntityQuery used to iterate CreationDefinition + Updated + (NetCourse | ObjectDefinition) for FillNodeMapJob. }}

  • private EntityQuery m_DeletedQuery
    {{ EntityQuery used for FillOldNodesJob to find nodes marked Deleted with Temp and PrefabRef. }}

  • private TypeHandle __TypeHandle
    {{ Internal cached collection of ComponentTypeHandle/ComponentLookup/BufferLookup used when scheduling jobs. }}

(There are many nested structs and job-local fields inside the job structs; see summary and source for details.)

Properties

  • None (no public properties on GenerateNodesSystem)

Constructors

  • public GenerateNodesSystem()
    {{ Default parameterless constructor. The system relies on OnCreate to initialize references to other systems and queries. }}

Methods

  • protected override void OnCreate()
    {{ Initializes references to other systems (ToolSystem, SearchSystem, TerrainSystem, GenerateObjectsSystem, ModificationBarrier1) and sets up the EntityQueries used by the system. Calls RequireForUpdate(m_DefinitionQuery) so the system runs only when relevant creation definitions are present. Marked [Preserve]. }}

  • protected override void OnUpdate()
    {{ Main update method. Creates temporary Native containers (NativeQueue, NativeList, NativeParallelHashMap for definition map, NativeParallelMultiHashMap for old nodes), schedules the Burst-compiled jobs in the right dependency order:

  • FillNodeMapJob (schedules in parallel over m_DefinitionQuery) — enqueues nodes to update/create based on CreationDefinition + NetCourse and spatial queries against net search tree

  • FillOldNodesJob (schedules on m_DeletedQuery) — builds map of existing (old) nodes for reuse matching
  • CollectUpdatesJob (single job) — consumes the update queue and merges/deduplicates updates into a list
  • CreateNodesJob (single job) — iterates merged update list and creates or reuses nodes via EntityCommandBuffer; sets many node-related components depending on flags and existing entity state

It also wires job handles into other systems (m_SearchSystem.AddNetSearchTreeReader, m_GenerateObjectsSystem.AddOwnerMapReader) and adds the CreateNodesJob handle to the ModificationBarrier. The method disposes Native containers with correct dependencies. }}

  • protected override void OnCreateForCompiler()
    {{ Internal helper overriding the compiler flow; assigns queries and type handles for the compiled system. }}

  • private void __AssignQueries(ref SystemState state)
    {{ Private helper that (in this compiled form) is a placeholder; it is called by OnCreateForCompiler to ensure queries are assigned (implementation here only creates and disposes a temporary EntityQueryBuilder). }}

  • (Multiple nested job structs contain many private helper methods important to understanding behavior, e.g. CreateNodesJob.TryGetOldEntity, FindNodePrefab, WillBeOrphan, CanDelete, etc.)

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // The system automatically grabs required systems and sets up queries in OnCreate.
    // If you need to interact with it from a mod, get the system from World:
    // var genNodes = World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<Game.Tools.GenerateNodesSystem>();
}

Additional notes for modders: - The heavy work is performed in Burst-compiled jobs for performance; patching or replacing behavior requires care to preserve job scheduling and dependencies. - CreateNodesJob uses an EntityCommandBuffer from ModificationBarrier1 — changes are applied after jobs finish; do not directly modify entity state from jobs. - The system attempts to reuse old node entities when possible by matching prefab/subprefab/original/owner and spatial proximity (OldNodeMap). If you add custom node-placement logic, consider how it affects reuse. - Editor mode, Standalone nodes, Owner reuse, elevation/parent mesh and LocalConnect semantics are all considered; test changes in both editor and runtime.

If you want, I can produce a more detailed description of any nested job (FillNodeMapJob, CreateNodesJob, FillOldNodesJob, CollectUpdatesJob) or extract specific component/flag interactions used during node creation.