Skip to content

Game.Serialization.ConnectedEdgeSystem

Assembly: Game (assembly name inferred; provided source is in Game namespace)
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
ConnectedEdgeSystem is a Unity Entities (DOTS) system that builds and updates ConnectedEdge buffers for node entities based on Edge components. It scans entities that contain Edge and/or ConnectedNode data, and for each Edge it registers the edge entity with the ConnectedEdge buffers of its start and end nodes. It also iterates ConnectedNode buffers (middle nodes) to deduplicate entries and add the edge to the corresponding ConnectedEdge buffers. The work is performed inside a Burst-compiled IJobChunk (ConnectedEdgeJob) and scheduled via JobChunkExtensions in OnUpdate. Missing ConnectedEdge buffers for referenced nodes are logged with UnityEngine.Debug.


Fields

  • private EntityQuery m_Query
    Used to select chunks/entities that the system operates on. The query matches entities that either have an Edge component or a ConnectedNode buffer (the original code creates an Any query on Edge (ReadOnly) and ConnectedNode (ReadWrite)). The system calls RequireForUpdate(m_Query) to only run when there are matching entities.

  • private TypeHandle __TypeHandle
    Compiler-generated container for cached type handles (EntityTypeHandle, ComponentTypeHandle, BufferTypeHandle, BufferLookup). It exposes a method to assign those handles from a SystemState so the job can access the appropriate chunk/lookup handles.

Properties

  • None (no public properties are defined on this system).

Constructors

  • public ConnectedEdgeSystem()
    Parameterless constructor annotated with [Preserve]. It is a default, compiler-generated constructor; no custom initialization is performed there (initialization is in OnCreate).

Methods

  • protected override void OnCreate()
    Called when the system is created. It builds the EntityQuery used by the system:
  • Query Any: ComponentType.ReadOnly(), ComponentType.ReadWrite()
  • Calls RequireForUpdate(m_Query) so the system will only update when there are entities matching the query.

  • protected override void OnUpdate()
    Prepares and schedules the Burst-compiled ConnectedEdgeJob. It initializes the job fields by obtaining the proper type handles via InternalCompilerInterface.Get* methods using the cached __TypeHandle entries and the system's CheckedStateRef. The job is scheduled with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and the returned JobHandle is stored back to base.Dependency.

  • protected override void OnCreateForCompiler()
    Compiler helper that calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef). This is used by code generation/compilation steps to ensure type handles are assigned for the system.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated helper that (in this build) creates and disposes an EntityQueryBuilder(Allocator.Temp). In full builds this is where additional queries would be assigned/initialized.

Nested types and their methods (summary):

  • ConnectedEdgeJob (private, BurstCompile, implements IJobChunk)
  • Fields:
    • EntityTypeHandle m_EntityType (ReadOnly in usage) — used to get Entity array for the current chunk
    • ComponentTypeHandle<Edge> m_EdgeType (ReadOnly) — used to read Edge components
    • BufferTypeHandle<ConnectedNode> m_ConnectedNodeType — used to access ConnectedNode buffers
    • BufferLookup<ConnectedEdge> m_ConnectedEdges — used to obtain and write to ConnectedEdge buffers for nodes
  • Methods:

    • public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
      Core job logic:
    • Gets the chunk's NativeArray and NativeArray and BufferAccessor.
    • Iterates over edges in the chunk:
      • Tries to GetBuffer for edge.m_Start and edge.m_End via m_ConnectedEdges.TryGetBuffer(...). If found, adds a ConnectedEdge wrapping the current edge Entity; if not found, logs a warning mentioning the edge entity Index:Version.
    • Iterates over the ConnectedNode buffers (for each entity with a ConnectedNode buffer):
      • For each ConnectedNode entry at index k:
      • Scans earlier entries (0..k-1) to deduplicate: if a previous entry references the same node, the current entry is removed (via dynamicBuffer.RemoveAt(k--) ) to avoid duplicates.
      • If not a duplicate, attempts to fetch the ConnectedEdge buffer for the referenced middle node and add the current edge entity to it; if the buffer is missing, logs a warning and removes the ConnectedNode entry.
    • void IJobChunk.Execute(...) — explicit interface implementation that forwards to the public Execute.
  • TypeHandle (private struct)

  • Fields (compiler-generated cached handles):
    • EntityTypeHandle __Unity_Entities_Entity_TypeHandle
    • ComponentTypeHandle<Edge> __Game_Net_Edge_RO_ComponentTypeHandle
    • BufferTypeHandle<ConnectedNode> __Game_Net_ConnectedNode_RW_BufferTypeHandle
    • BufferLookup<ConnectedEdge> __Game_Net_ConnectedEdge_RW_BufferLookup
  • Methods:
    • public void __AssignHandles(ref SystemState state)
      Assigns each handle from the provided SystemState:
    • GetEntityTypeHandle()
    • GetComponentTypeHandle(isReadOnly: true)
    • GetBufferTypeHandle()
    • GetBufferLookup()

Notes on logging and safety: - The job uses BufferLookup.TryGetBuffer which may fail if the referenced node entity does not have a ConnectedEdge buffer. In such cases the system logs a message using UnityEngine.Debug.Log with the offending edge entity Index:Version. - The code performs in-place modification of DynamicBuffer (RemoveAt with index adjustments) while iterating; care is taken to decrement the iterator when removal occurs. - The job is Burst-compiled (BurstCompile attribute) to improve performance.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_Query = GetEntityQuery(new EntityQueryDesc
    {
        Any = new ComponentType[2]
        {
            ComponentType.ReadOnly<Edge>(),
            ComponentType.ReadWrite<ConnectedNode>()
        }
    });
    RequireForUpdate(m_Query);
}

[Preserve]
protected override void OnUpdate()
{
    var jobData = new ConnectedEdgeJob
    {
        m_EntityType = InternalCompilerInterface.GetEntityTypeHandle(ref __TypeHandle.__Unity_Entities_Entity_TypeHandle, ref base.CheckedStateRef),
        m_EdgeType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Net_Edge_RO_ComponentTypeHandle, ref base.CheckedStateRef),
        m_ConnectedNodeType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Net_ConnectedNode_RW_BufferTypeHandle, ref base.CheckedStateRef),
        m_ConnectedEdges = InternalCompilerInterface.GetBufferLookup(ref __TypeHandle.__Game_Net_ConnectedEdge_RW_BufferLookup, ref base.CheckedStateRef)
    };
    base.Dependency = JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency);
}

If you need, I can also: - Produce a shorter summary for modders (what to add to their entities to participate). - Extract the nested job into a stand-alone example showing how to add ConnectedEdge buffers to node entities before running the system. - Annotate expected component definitions for Edge, ConnectedNode, and ConnectedEdge if you provide them.