Skip to content

Game.PlaceableNetData

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

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
PlaceableNetData is a small ECS component that stores placement and cost-related metadata for "placeable net" prefabs (typically road/rail network prefabs) used by the game. It contains elevation constraints, links to an underground prefab, flags controlling placement behavior and upgrade composition, default economic values (construction/upkeep), snapping distance used during placement, minimum water elevation, and XP reward. The struct implements a simple binary serialization that (currently) persists the placement flags and sets a default snap distance on deserialization.


Fields

  • public Bounds1 m_ElevationRange
    Defines the allowed elevation interval (min/max) for placing this net prefab. Bounds1 comes from Colossal.Mathematics and is used to enforce elevation placement constraints.

  • public Entity m_UndergroundPrefab
    Reference to an Entity representing an underground variant of the prefab (if any). This is an ECS Entity handle, typically a prefab entity used when placing the underground version.

  • public PlacementFlags m_PlacementFlags
    Bitmask of placement flags that control placement rules and behaviors (e.g., whether underground placement is allowed, snapping rules, lane/segment placement behaviors). This is serialized to disk as a uint.

  • public CompositionFlags m_SetUpgradeFlags
    Composition flags to set when applying an upgrade (used when this prefab is used as an upgrade target). Controls what composition bits should be enabled.

  • public CompositionFlags m_UnsetUpgradeFlags
    Composition flags to clear when applying an upgrade. Controls what composition bits should be disabled.

  • public uint m_DefaultConstructionCost
    Default construction cost (in game currency) used for this placeable net when calculating build costs.

  • public float m_DefaultUpkeepCost
    Default upkeep cost (recurring) used for this net.

  • public float m_SnapDistance
    Snap distance used while placing the prefab (how close placement must be to valid snapping points). Note: Deserialize sets this to 8f as a fallback/default.

  • public float m_MinWaterElevation
    Minimum water elevation allowed for placement. Used to prevent placing certain nets too low relative to water level.

  • public int m_XPReward
    Experience reward (XP) awarded on placing the prefab (if applicable).

Properties

  • This struct does not define any C# properties beyond its public fields. It implements interfaces required by ECS and the game's serialization system.

Constructors

  • public PlaceableNetData() (default struct constructor)
    No explicit constructor is declared. The default value-initialized struct is used in ECS contexts. Note that some fields (e.g., m_SnapDistance) are given a fallback value during deserialization.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes component data. Current implementation writes only the placement flags:
  • Writes (uint)m_PlacementFlags to the writer. This is a minimal serialization; other fields are not serialized here (they may be handled elsewhere or use defaults).

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes component data. Current implementation:

  • Reads a uint from reader into a local value and assigns it to m_PlacementFlags.
  • Sets m_SnapDistance = 8f as a default/fallback value after reading flags. Note: Because only placement flags are read from the stream, other fields remain at their default values unless set elsewhere.

Usage Example

// Example: creating and initializing a PlaceableNetData instance manually
PlaceableNetData netData = new PlaceableNetData
{
    m_ElevationRange = new Bounds1(min: -100f, max: 200f),
    m_UndergroundPrefab = Entity.Null, // or a valid prefab entity
    m_PlacementFlags = PlacementFlags.AllowUnderground | PlacementFlags.SnapToGrid,
    m_SetUpgradeFlags = CompositionFlags.None,
    m_UnsetUpgradeFlags = CompositionFlags.None,
    m_DefaultConstructionCost = 250u,
    m_DefaultUpkeepCost = 1.5f,
    m_SnapDistance = 8f,
    m_MinWaterElevation = -10f,
    m_XPReward = 5
};

// The component can be added to an entity in ECS:
// e.g., entityManager.AddComponentData(entity, netData);

// Serialization example (writer must implement IWriter)
// writer.Write((uint)netData.m_PlacementFlags);

// Deserialization note:
// When Deserialize is invoked by the game's serializer, it reads placement flags and
// ensures m_SnapDistance defaults to 8f:
[Preserve]
public void OnDeserialize<TReader>(TReader reader) where TReader : IReader
{
    PlaceableNetData pd = new PlaceableNetData();
    pd.Deserialize(reader);
    // pd.m_SnapDistance will be 8f if not otherwise populated
}

Additional notes: - PlacementFlags and CompositionFlags are bitmask enums defined elsewhere in the game code; treat them as flags rather than single values. - m_UndergroundPrefab is an ECS Entity reference — when referencing prefab entities ensure those prefabs are loaded/registered with the EntityManager. - Because this struct's Serialize/Deserialize currently only handle placement flags explicitly, other fields may rely on default values or be serialized elsewhere in the prefab/resource pipeline. When modding, be cautious: changing serialization expectations can break save/load compatibility.