Skip to content

Game.Prefabs.NetSectionPiece

Assembly:
Assembly-CSharp (game assembly) — this type is defined in the game's runtime assemblies used by Cities: Skylines 2 mods.
Namespace:
Game.Prefabs

Type:
struct (IBufferElementData)

Base:
System.ValueType, implements Unity.Entities.IBufferElementData

Summary:
NetSectionPiece is a buffer element used to store information about an individual piece associated with a network section (for example a road/track piece within a section). The struct holds an Entity reference to the piece and several bitflag fields that describe composition and section filtering rules, plus a positional offset. The struct is annotated with [InternalBufferCapacity(0)], meaning it is used as a dynamic buffer on entities (initial capacity 0).


Fields

  • public Entity m_Piece
    Reference to the piece Entity represented by this buffer element. This is the entity for the actual piece prefab instance belonging to the section.

  • public CompositionFlags m_CompositionAll
    Bitflags describing composition requirements that must all be present for this piece to be considered valid. (CompositionFlags is an enum/bitmask defined elsewhere in the game.)

  • public CompositionFlags m_CompositionAny
    Bitflags describing composition requirements where any matching bit is sufficient for the piece to be considered valid.

  • public CompositionFlags m_CompositionNone
    Bitflags describing composition masks that must not be present (negation) for this piece to be valid.

  • public NetSectionFlags m_SectionAll
    Bitflags describing section attributes that must all be present for this piece to be applicable to the section.

  • public NetSectionFlags m_SectionAny
    Bitflags describing section attributes where any matching attribute makes this piece applicable.

  • public NetSectionFlags m_SectionNone
    Bitflags describing section attributes that must not be present for the piece to apply.

  • public NetPieceFlags m_Flags
    Bitflags specific to the piece (behavior, special rendering flags, etc.). See NetPieceFlags enum for details.

  • public float3 m_Offset
    Local offset for the piece (float3) relative to the section or anchor point. Used to position the piece within the section.

Notes: - The flag types (CompositionFlags, NetSectionFlags, NetPieceFlags) are typically enums used as bitmasks in the game; consult their definitions for possible values. - Because this struct implements IBufferElementData, instances are stored in a DynamicBuffer on an entity (usually the net section entity).

Properties

  • This type does not declare any properties. It is a plain data buffer element (fields only).

Constructors

  • public NetSectionPiece()
    Default value-type constructor (provided implicitly). For buffer elements, you typically set fields explicitly when adding to a DynamicBuffer.

Methods

  • This type does not declare any methods. It is a POD (plain-old-data) struct intended for storage in an ECS dynamic buffer.

Usage Example

// Add a dynamic buffer to an entity (e.g., net section entity) and populate it:
Entity sectionEntity = /* the section entity */;
Entity pieceEntity = /* the piece entity */;

// Add buffer (if not already present)
if (!EntityManager.HasComponent<NetSectionPiece>(sectionEntity))
{
    EntityManager.AddBuffer<NetSectionPiece>(sectionEntity);
}

// Get the dynamic buffer and add an element
var buffer = EntityManager.GetBuffer<NetSectionPiece>(sectionEntity);

NetSectionPiece element = new NetSectionPiece
{
    m_Piece = pieceEntity,
    m_CompositionAll = CompositionFlags.None,
    m_CompositionAny = CompositionFlags.None,
    m_CompositionNone = CompositionFlags.None,
    m_SectionAll = NetSectionFlags.None,
    m_SectionAny = NetSectionFlags.None,
    m_SectionNone = NetSectionFlags.None,
    m_Flags = NetPieceFlags.None,
    m_Offset = new float3(0f, 0f, 0f)
};

buffer.Add(element);

// Reading and modifying buffer elements in a system (example in an ECS SystemBase)
Entities
    .WithAll<SomeSectionTag>()
    .ForEach((Entity e, DynamicBuffer<NetSectionPiece> pieces) =>
    {
        for (int i = 0; i < pieces.Length; i++)
        {
            ref NetSectionPiece p = ref pieces.ElementAt(i); // get by ref to modify
            // Read fields
            Entity pieceEnt = p.m_Piece;
            float3 offset = p.m_Offset;

            // Example modification
            p.m_Offset = offset + new float3(0f, 0.1f, 0f);
        }
    }).ScheduleParallel();

Additional tips: - Ensure that the flag enums you assign match the bitmask expectations in the game's code (use enum values defined by the game). - Because this is a dynamic buffer element, avoid storing managed/reference types here — only blittable value types are appropriate. - Use DynamicBuffer.AsNativeArray or iteration APIs for performant access in jobs/systems.