Game.Net.LaneHiddenSystem
Assembly: Assembly-CSharp.dll (in-game Game assembly)
Namespace: Game.Net
Type: class
Base: GameSystemBase
Summary: LaneHiddenSystem is an ECS system used by Cities: Skylines 2 to keep Hidden state in sync for lane entities and their sub-lanes. It uses a Burst-compiled IJobChunk (HiddenSubObjectJob) and a ModificationBarrier5 command buffer to add or remove the Hidden component and to mark affected entities with BatchesUpdated. The system: - Ensures sub-lane entities have the Hidden component when their parent lane buffers reference them. - Removes Hidden from lane entities when their Owner's owner entity is not hidden. The system is scheduled in parallel and uses type handles / component lookups cached in a nested TypeHandle struct.
Fields
-
private ModificationBarrier5 m_ModificationBarrier
Used to create an EntityCommandBuffer (parallel writer) for safely adding/removing components from the job. ModificationBarrier5 ensures commands are applied at the appropriate synchronization point. -
private EntityQuery m_HiddenQuery
EntityQuery selecting entities that have the Hidden component and either a SubLane buffer or a Lane component. This query is used to require the system to update only when relevant entities exist/changed. -
private TypeHandle __TypeHandle
Container for cached type handles (EntityTypeHandle, BufferTypeHandle, ComponentTypeHandle , ComponentLookup ) used by the job to efficiently access component data. -
private struct HiddenSubObjectJob
(nested) Burst-compiled IJobChunk that: - For chunks with a SubLane buffer: iterates sub-lanes and adds Hidden + BatchesUpdated to sub-lane entities that lack Hidden.
-
For other chunks: checks Owner components and removes Hidden + adds BatchesUpdated for lane entities whose owner entity is not hidden. It writes commands through an EntityCommandBuffer.ParallelWriter.
-
private struct TypeHandle
(nested) Holds the type handles and provides __AssignHandles(ref SystemState) to initialize them from a SystemState.
Properties
- None (no public properties exposed by this system)
Constructors
public LaneHiddenSystem()
Default constructor. The system also uses [Preserve] attributes on lifecycle methods to ensure IL2CPP/stripping safety when required.
Methods
protected override void OnCreate() : System.Void
Called when the system is created. Responsibilities:- Acquires the ModificationBarrier5 system from the world.
- Creates m_HiddenQuery that matches entities with Hidden and either SubLane or Lane.
-
Calls RequireForUpdate(m_HiddenQuery) so the system runs only when relevant entities exist.
-
protected override void OnUpdate() : System.Void
Schedules the HiddenSubObjectJob in parallel. Passes in: - EntityTypeHandle, BufferTypeHandle
, ComponentTypeHandle , ComponentLookup via InternalCompilerInterface getters. -
A parallel EntityCommandBuffer generated from m_ModificationBarrier. After scheduling, the job handle is registered with the modification barrier and assigned to base.Dependency.
-
protected override void OnCreateForCompiler() : System.Void
Compiler-time helper that ensures __AssignQueries and type handles are initialized. Calls __AssignQueries and TypeHandle.__AssignHandles for codegen/IL2CPP safety. -
private void __AssignQueries(ref SystemState state)
Internal helper used by OnCreateForCompiler to assign any queries required by the system (empty in the decompiled source aside from a temp EntityQueryBuilder disposal). -
private struct TypeHandle.__AssignHandles(ref SystemState state)
Initializes and caches the EntityTypeHandle, BufferTypeHandle, ComponentTypeHandle , and ComponentLookup from the given SystemState. -
HiddenSubObjectJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Job logic described above. Uses: - BufferAccessor
to detect sub-lane buffers and call EnsureHidden for each dynamic buffer. - For non-sub-lane chunks, iterates Owner components and removes Hidden from lane entities where the owner is not hidden.
- Writes add/remove component commands via m_CommandBuffer (parallel writer). Also contains EnsureHidden which collects sub-lane entities missing Hidden and adds Hidden + BatchesUpdated to them.
Notes: - Adds or removes the Hidden component and also adds the BatchesUpdated marker to trigger subsequent processing of batches. - Uses StackList (stackalloc backed list) to batch up entities per-chunk for single command buffer calls, reducing command overhead.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire the modification barrier system and build an entity query that matches:
// entities with Hidden and (SubLane or Lane).
m_ModificationBarrier = base.World.GetOrCreateSystemManaged<ModificationBarrier5>();
m_HiddenQuery = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[1] { ComponentType.ReadOnly<Hidden>() },
Any = new ComponentType[2]
{
ComponentType.ReadOnly<SubLane>(),
ComponentType.ReadOnly<Lane>()
},
None = new ComponentType[0]
});
RequireForUpdate(m_HiddenQuery);
}
protected override void OnUpdate()
{
// Schedule the burst-compiled job in parallel. The job will add/remove Hidden and
// tag affected entities with BatchesUpdated via the modification barrier's command buffer.
var jobHandle = JobChunkExtensions.ScheduleParallel(new HiddenSubObjectJob
{
m_EntityType = InternalCompilerInterface.GetEntityTypeHandle(ref __TypeHandle.__Unity_Entities_Entity_TypeHandle, ref base.CheckedStateRef),
m_SubLaneType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Net_SubLane_RO_BufferTypeHandle, ref base.CheckedStateRef),
m_OwnerType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Common_Owner_RO_ComponentTypeHandle, ref base.CheckedStateRef),
m_HiddenData = InternalCompilerInterface.GetComponentLookup(ref __TypeHandle.__Game_Tools_Hidden_RO_ComponentLookup, ref base.CheckedStateRef),
m_CommandBuffer = m_ModificationBarrier.CreateCommandBuffer().AsParallelWriter()
}, m_HiddenQuery, base.Dependency);
m_ModificationBarrier.AddJobHandleForProducer(jobHandle);
base.Dependency = jobHandle;
}
Additional notes for modders: - This system runs inside the Entities/DOTS framework used by the game. Modifying or interfering with the Hidden component behavior can affect rendering/visibility and batch updates for lanes and sub-lanes. - BatchesUpdated is used as a marker so downstream systems re-batch or refresh rendering/physics for changed lane entities — do not remove that marker unless you understand the wider pipeline consequences. - The system uses Burst and low-level constructs (stackalloc, StackList) for performance; any manual reimplementation should keep similar batching and command-buffer usage for thread-safety and efficiency.