Skip to content

Game.Prefabs.NetObject

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
NetObject is a prefab component used for network-related placeable objects (roads, tracks, nodes, stops, etc.). It declares the piece composition requirements and required/pass-through road/track types, configures placement flags (road node/edge, waterway, attached) and copies these settings into the ECS components NetObjectData and PlaceableObjectData during initialization. It also applies a node offset to the PlaceableObjectData placement offset and logs an error if invalid section flags were requested.


Fields

  • public NetPieceRequirements[] m_SetCompositionState
    Array describing required net piece composition flags (used to compute composition flags stored in NetObjectData).

  • public RoadTypes m_RequireRoad
    Specifies what RoadTypes are required for placement (e.g., Car). During Initialize, this is written to NetObjectData.m_RequireRoad. Additionally, if m_RequireRoad is RoadTypes.Car and m_SetCompositionState contains ShipStop, Watercraft is added to this requirement.

  • public RoadTypes m_RoadPassThrough
    RoadTypes that this object allows to pass through (written to NetObjectData.m_RoadPassThrough).

  • public TrackTypes m_TrackPassThrough
    TrackTypes that this object allows to pass through (written to NetObjectData.m_TrackPassThrough).

  • public float m_NodeOffset
    Z-offset applied to placement; on Initialize this value is copied to PlaceableObjectData.m_PlacementOffset.z to adjust the placement height for nodes.

  • public bool m_Attached = true
    When true, the PlaceableObjectData will be marked with the Attached placement flag.

Properties

  • This class does not declare public properties. It exposes behavior via its public fields and via overridden ComponentBase methods that populate ECS components.

Constructors

  • public NetObject()
    Default parameterless constructor (compiler-provided). No custom initialization is performed in a user-defined constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() and ComponentType.ReadWrite() to the given HashSet so the prefab creation system knows which ECS components to attach to entities created from this prefab.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Requests the Game.Objects.NetObject (managed object) component type for the archetype by adding ComponentType.ReadWrite().

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Main initialization logic:

  • Calls NetCompositionHelpers.GetRequirementFlags(m_SetCompositionState, out componentData.m_CompositionFlags, out sectionFlags) to compute composition flags. If sectionFlags != 0, logs an error indicating unsupported section flags for this prefab.
  • Writes m_RequireRoad, m_RoadPassThrough and m_TrackPassThrough into the NetObjectData instance and sets that component on the entity. If m_RequireRoad is Car and any NetPieceRequirements == ShipStop are present, adds Watercraft to m_RequireRoad.
  • Retrieves PlaceableObjectData from the entity, sets PlacementFlags.NetObject and adjusts m_PlacementOffset.z to m_NodeOffset.
  • Based on the computed composition flags, sets PlacementFlags.RoadNode (if node bits present) and/or PlacementFlags.RoadEdge (if edge bits or no node bits). Also sets SubReplacementType.None when modifying those flags.
  • If the object requires watercraft roads, sets PlacementFlags.Waterway.
  • If m_Attached is true, sets PlacementFlags.Attached.
  • Writes the modified PlaceableObjectData back to the entity.

Usage Example

// Example: configuring a NetObject prefab instance in code (e.g., editor tool)
// Note: in typical modding, prefabs are edited in the asset/prefab authoring workflow.
// This snippet simply shows how the public fields affect initialization.

NetObject netPrefab = somePrefab.GetComponent<NetObject>();
if (netPrefab != null)
{
    // Change vertical placement of nodes
    netPrefab.m_NodeOffset = 1.25f;

    // Make sure the object is attached to the net
    netPrefab.m_Attached = true;

    // Require car roads (and allow through boats if ShipStop is in composition)
    netPrefab.m_RequireRoad = RoadTypes.Car;
    netPrefab.m_RoadPassThrough = RoadTypes.None;
    netPrefab.m_TrackPassThrough = TrackTypes.None;

    // When the game creates the entity for this prefab, Initialize(...) will
    // copy these values into NetObjectData and PlaceableObjectData, set placement
    // flags (RoadNode/RoadEdge/Waterway/Attached), and set m_PlacementOffset.z.
}

Notes and modding tips: - Composition flags are computed via NetCompositionHelpers.GetRequirementFlags using m_SetCompositionState. If you see error logs mentioning section flags, review the NetPieceRequirements array values — some combinations are invalid for prefabs.
- Prefer editing prefab fields in your prefab authoring workflow (asset/prefab editor) rather than modifying them at runtime unless you know how prefab re-initialization will be handled.
- PlaceableObjectData flags determine how the placement system treats the object (whether it can be placed on edges or nodes, whether it’s attached to other network pieces, and whether it is a waterway). Adjust m_SetCompositionState and m_RequireRoad appropriately to get desired placement behavior.