Game.Prefabs.NetCompositionSystem
Assembly: Game
Namespace: Game.Prefabs
Type: class
Base: GameSystemBase
Summary:
NetCompositionSystem is an ECS system responsible for building and finalizing "net" (road/track/waterway/pathway/taxiway/terrain) composition data for prefab entities. It runs a Burst-compiled IJobChunk (InitializeCompositionJob) over prefab archetypes that have composition buffers and mesh references, computes aggregate composition metadata (widths, heights, LODs, flags), generates lane lists, placed objects, areas and crosswalks, and fills specialized composition components such as RoadComposition, TrackComposition, WaterwayComposition, PathwayComposition, TaxiwayComposition and TerrainComposition. The system is scheduled only when prefabs that require composition exist (RequireForUpdate on a query) and uses many read-only ComponentLookup/BufferLookup handles to read piece/mesh/prefab-specific data in the job.
Fields
-
private EntityQuery m_CompositionQuery
This query selects prefab entities that require composition initialization. OnCreate sets this query to require NetCompositionData, NetCompositionPiece buffers and a NetCompositionMeshRef and Created marker, so the system only runs when there are prefabs to process. -
private TypeHandle __TypeHandle
Internal holder for component and buffer type handles / lookups used by the system and the job. __TypeHandle.__AssignHandles(ref state) populates ComponentTypeHandle, BufferTypeHandle, ComponentLookup and BufferLookup fields used when creating the InitializeCompositionJob.
Properties
- (none on the top-level NetCompositionSystem)
Constructors
public NetCompositionSystem()
Default constructor. Marked with [Preserve] to survive code stripping. Initialization of queries and handles happens in OnCreate and OnCreateForCompiler.
Methods
protected override void OnCreate()
Called by the ECS runtime when the system is created. It:- Builds m_CompositionQuery to require: NetCompositionData (RW), NetCompositionPiece (RW buffer), NetCompositionMeshRef (RO), and Created (RO).
- Calls RequireForUpdate(m_CompositionQuery) so the system only updates when matching entities exist.
-
Marked with [Preserve].
-
protected override void OnUpdate()
Creates and schedules an InitializeCompositionJob (Burst-compiled) to process matching chunks in parallel. The job receives ComponentTypeHandle and BufferTypeHandle instances (via InternalCompilerInterface.Get*Handle) and a number of ComponentLookup/BufferLookup read-only handles for piece/mesh/prefab data (NetPieceData, NetLaneData, NetGeometryData, MeshData, RoadData, TrackData, etc.). The job: - Iterates composition chunks and computes/updates NetCompositionData (width/height/flags/state), calls helpers to compute min LOD and placeable data.
- Builds lane information into NetCompositionLane buffers.
- Adds NetCompositionObject entries using per-piece NetPieceObject buffers (handles spacing/priority/preserving shapes, streetlight grouping, flip/invert handling).
- Adds NetCompositionArea entries using per-piece NetPieceArea buffers (respecting bridge/no-bridge flags and section inversion).
- Detects and adds crosswalk information from NetCrosswalkData and piece lane positions.
- Fills RoadComposition, TrackComposition, WaterwayComposition, PathwayComposition, TaxiwayComposition and TerrainComposition with data taken from corresponding Data components (RoadData, TrackData, WaterwayData, PathwayData, TaxiwayData, NetTerrainData, BridgeData, PrefabData).
- Schedules the job via JobChunkExtensions.ScheduleParallel; result is stored in base.Dependency.
Notes: - The main work is in InitializeCompositionJob.Execute (Burst-compiled). - Many lookups are read-only; the job writes to composition components and composition buffers. - The job uses temporary NativeList allocations per chunk for lane aggregation.
-
protected override void OnCreateForCompiler()
Internal helper used in generated/compiled code. It assigns query and type handles by calling __AssignQueries and __TypeHandle.__AssignHandles(ref state). Ensures handles are initialized for the compiler/runtime. -
private void __AssignQueries(ref SystemState state)
Assigns up any queries needed for compiler-time initialization. Present to satisfy generated/compiled-on-build requirements; currently creates and disposes a temporary EntityQueryBuilder. -
Nested types (summary)
-
private struct InitializeCompositionJob : IJobChunk
Burst-compiled chunk job that contains the core logic for composition initialization and helper methods:- Execute(...) — top-level per-chunk processing (see description above).
- AddCompositionAreas(Entity, NetCompositionData, DynamicBuffer
, DynamicBuffer , bool isBridge) — collects area fragments from piece area buffers, applies inversion and bridge filtering. - public static void AddCompositionObjects(Entity, NetCompositionData, DynamicBuffer
, DynamicBuffer , ComponentLookup , ComponentLookup , ComponentLookup , ComponentLookup , BufferLookup ) — gathers objects from piece object buffers, handles inversion/flip, spacing rules, streetlight grouping, combine/avoid rules and overwrites based on flags. - private void AddCompositionCrosswalks(Entity, NetCompositionData, DynamicBuffer
, DynamicBuffer ) — aggregates crosswalk extents from pieces and emits NetCompositionCrosswalk entries.
-
private struct TypeHandle
Container for all ComponentTypeHandle, BufferTypeHandle, ComponentLookup and BufferLookup fields used by InitializeCompositionJob. It exposes __AssignHandles(ref SystemState) to populate those handles.
Usage Example
This system runs automatically if prefab entities contain the required components. To make a prefab processed by NetCompositionSystem, ensure it has the composition buffers, a mesh ref and a Created marker. Example (pseudo-code — game type names used as in runtime):
// Assume entity is a prefab entity you created/modified.
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
// Ensure the prefab has composition data and a mesh ref buffer
if (!em.HasComponent<NetCompositionData>(prefabEntity))
em.AddComponentData(prefabEntity, new NetCompositionData());
if (!em.HasComponent<NetCompositionMeshRef>(prefabEntity))
em.AddComponentData(prefabEntity, new NetCompositionMeshRef { /* fill as appropriate */ });
// Add the Created tag so the system will include it in the composition query
if (!em.HasComponent<Created>(prefabEntity))
em.AddComponent<Created>(prefabEntity);
// The NetCompositionSystem will detect the prefab and schedule a Burst job
// to calculate/wrap up composition, lanes, objects, areas and crosswalks.
// No direct API call is required; the system runs on the next update.
Notes for modders: - If you add custom NetPieceObject/NetPieceArea/NetPieceLane/NetCrosswalkData/etc. to new pieces, make sure the corresponding Component/Buffer types are available at runtime; InitializeCompositionJob uses many read-only lookups to access those. - The job is Burst-compiled and runs in parallel over chunks. Avoid modifying the referenced component types from other systems in ways that would invalidate lookups between scheduling and completion. - The system relies on PrefabData/NetGeometryData/MeshData and other Data components to compute sizes, LODs and flags — ensure your custom net piece/prefab provides correct Data components.