Game.ValidationSystem
Assembly:
Assembly-CSharp.dll
Namespace:
Game.Tools
Type:
class
Base:
GameSystemBase
Summary:
ValidationSystem is a large ECS SystemBase responsible for validating game entities (objects, nets, edges, lanes, areas, buildings, routes, water sources, brushes, etc.) each frame or when entities are updated. It collects bounds for objects and edges, builds search structures, schedules multiple Burst-compiled jobs (BoundsListJob, ValidationJob, CollectAreaTrianglesJob, ValidateAreaTrianglesJob, FillErrorPrefabsJob, ProcessValidationResultsJob and helper jobs/structs) and processes validation errors into icon/notification commands. The system coordinates with many other subsystems (search systems, instance counts, city/money, icon command, water/terrain/groundwater systems) and uses command buffers and Native containers to produce/clear error, warning and override components for entities.
Fields
-
private ModificationEndBarrier m_ModificationBarrier
Used to create command buffers for applying component changes as a result of validation (adding/removing Error/Warning/Override/BatchesUpdated and setting Temp flags). -
private ToolSystem m_ToolSystem
Reference to the ToolSystem to determine editor vs game mode and applyMode state. -
private Components m_Components
Nested helper system instance (ValidationSystem.Components) which itself updates component-related state and maintains a NativeHashMap of entity error severities. -
private Game.Objects.SearchSystem m_ObjectSearchSystem
Search system used to find nearby objects for validation queries. -
private Game.Net.SearchSystem m_NetSearchSystem
Search system used to find nearby net elements (nodes/edges/tracks). -
private Game.Areas.SearchSystem m_AreaSearchSystem
Search system used for area-related searches. -
private InstanceCountSystem m_InstanceCountSystem
Provides instance counts per prefab (used for instance-limit validations). -
private CitySystem m_CitySystem
Used to query the city entity (for player money lookups etc). -
private IconCommandSystem m_IconCommandSystem
System used to produce validation icons on the map (error/warning/info). -
private WaterSystem m_WaterSystem
Provides water surface data used for water-aware validations. -
private TerrainSystem m_TerrainSystem
Provides terrain height data used in validations. -
private GroundWaterSystem m_GroundWaterSystem
Provides groundwater map for validations that depend on groundwater. -
private EntityQuery m_UpdatedQuery
Query selecting Temp + Updated entities (exclude Deleted/Relative/Moving/Stopped). This drives main validation when something changed. -
private EntityQuery m_UpdatedAreaQuery
Query selecting updated Area entities (Temp + Updated + Area) to collect triangles for per-triangle validation. -
private EntityQuery m_ToolErrorPrefabQuery
Query used to find notification/error prefab entities that map error types to icon prefabs (ToolErrorData). -
private ChunkType m_ChunkType
ChunkType struct instance: precomputed ComponentTypeHandles and BufferTypeHandles used by jobs to read entity/chunk data. -
private EntityData m_EntityData
EntityData struct instance: ComponentLookup/BufferLookup wrappers used by jobs for reading component data by entity. -
private TypeHandle __TypeHandle
Internal type-handle helper containing ComponentTypeHandle/Lookup assignments used in job scheduling and OnCreateForCompiler.
Properties
- (none public)
ValidationSystem is a system class and does not expose public properties in this file. It uses private fields to hold references to other systems and queries.
Constructors
public ValidationSystem()
Default constructor. The system depends on ECS lifecycle: OnCreate initializes queries, system references and helper structs; OnUpdate schedules validation jobs when updates are detected.
Methods
-
protected override void OnCreate()
Initializes references to required systems, creates entity queries (m_UpdatedQuery, m_UpdatedAreaQuery, m_ToolErrorPrefabQuery), constructs ChunkType and EntityData instances, and calls RequireForUpdate(m_UpdatedQuery) so that the system only runs when there are updated Temp entities. Also initializes the nested Components system instance. -
protected override void OnUpdate()
Main driver that: - Allocates temporary Native containers (edgeList, objectList, error queues, errorPrefabs).
- Produces an ArchetypeChunk list for updated entities.
- Updates chunk/entity handles (m_ChunkType.Update, m_EntityData.Update).
- Schedules BoundsListJob to collect bounds and sort lists.
- Prepares and schedules ValidationJob (IJobParallelForDefer) to validate objects/edges/lanes/areas/routes/brushes/water sources in parallel, generating ErrorData in queues.
- Optionally collects area triangles and schedules per-triangle validation (CollectAreaTrianglesJob + ValidateAreaTrianglesJob).
- Schedules FillErrorPrefabsJob (to map ToolErrorData -> prefab entity).
- Schedules ProcessValidationResultsJob to consume errors, compute icons, cancel optional temps based on money, add Error/Warning/Override components and issue icon commands.
- Wires up dependencies between jobs and registers readers with the search/instance/water/terrain systems.
-
Ensures proper disposal and AddJobHandleForProducer calls for command buffers and icon command system.
-
protected override void OnCreateForCompiler()
Compiler helper that assigns query/type handles used when compiling the system into Burst jobs and ensures __TypeHandle.__AssignHandles(ref base.CheckedStateRef) is called. -
private void __AssignQueries(ref SystemState state)
Internal helper used by OnCreateForCompiler to instantiate queries used by the system in the compiled code path (empty builder here). -
(Nested) Components.OnCreate() / OnUpdate()
The nested Components system initializes its own queries and maintains a NativeHashMap m_ErrorMap; it schedules UpdateComponentsJob to add/remove Error/Warning/Override components and BatchesUpdated components based on the map and the current entity components. This nested system is created and its m_ErrorMap is used by the outer ValidationSystem. -
(Numerous nested structs/jobs)
BoundsListJob, ValidationJob, CollectAreaTrianglesJob, ValidateAreaTrianglesJob, FillErrorPrefabsJob, ProcessValidationResultsJob and helper comparers and icon key/value types implement the heavy lifting of validation, error-collection, icon aggregation and command-buffer writes. These are Burst-compiled and operate with Native containers and search trees.
Usage Example
// Example: obtain the ValidationSystem from another system and ensure it exists.
// You normally don't call OnUpdate manually; the system runs automatically when Temp + Updated entities change.
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
var validationSystem = World.GetOrCreateSystemManaged<Game.Tools.ValidationSystem>();
// Validation system will run automatically when updates exist.
}
Notes: - The ValidationSystem is tightly integrated with the game's ECS component types (Temp, Owner, PrefabRef, EdgeGeometry, Area/Triangle buffers, etc.) and with other game-specific systems. It should not be replaced without understanding the job dependencies and Native containers used. - Many operations are Burst-compiled and use NativeJob patterns — be careful when modifying to preserve safety attributes and dependency setup.