Game.Prefabs.RoadPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: NetGeometryPrefab
Summary:
RoadPrefab is the prefab description for road network geometry used by the game. It captures the road type, speed limit and flags that affect traffic/placement rules, and can optionally link to a ZoneBlockPrefab to enable zoning-related components. The class overrides prefab dependency resolution and the set of ECS components that must be present on archetypes that represent road edges, nodes or net composition data. This prefab is used when registering or creating road assets for the Cities: Skylines 2 simulation and determines which runtime components will be added to entities created from the prefab.
Fields
-
public RoadType m_RoadType
Type of road (visual/functional classification). Controls which Road assets/visuals and rules are applied to entities created from this prefab. -
public float m_SpeedLimit = 100f
Maximum allowed speed on this road in game units (default 100f). Use to affect traffic simulation and routing. -
public ZoneBlockPrefab m_ZoneBlock
Optional reference to a ZoneBlockPrefab. When set, additional zoning-related components (SubBlock, ConnectedBuilding, service coverage, density, etc.) will be added to the archetype for road edges to enable building adjacency and zoning interactions. -
public bool m_TrafficLights
Flag indicating whether intersections on this road type should support traffic lights. Affects traffic simulation/AI decisions at nodes. -
public bool m_HighwayRules
Flag that changes placement/adjacency rules for this road. When true, certain connected-building behavior is suppressed so highways do not act like buildable-street edges.
Properties
public override IEnumerable<string> modTags
Returns the base modTags plus the tag "Roads". This property is used to categorize the prefab for mod filters, asset browsers or tooling; clients iterating modTags will receive the inherited tags and the "Roads" tag.
Constructors
public RoadPrefab()
Implicit default constructor. RoadPrefab instances are typically created as Unity prefab assets; mod code can instantiate or configure them via the Unity editor or scripts.
Methods
-
public override void GetDependencies(List<PrefabBase> prefabs)
Adds dependent prefabs that must be loaded before this prefab. RoadPrefab adds its m_ZoneBlock (if not null) to the provided prefabs list and otherwise defers to the base implementation. Use this so the ZoneBlockPrefab is available when archetypes/components are computed. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types that must be present on any entity created from this prefab. This implementation ensures RoadData is included (in addition to whatever the base class requires), so runtime systems expecting RoadData will be able to operate. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Modifies the archetype component set depending on the context (edge, node or composition). Behavior: - If the component set already contains
Edge
:- Adds:
Road
,UpdateFrame
,LandValue
,EdgeColor
,NetCondition
,MaintenanceConsumer
,BorderDistrict
. - If
m_ZoneBlock != null
, additionally adds:SubBlock
,ConnectedBuilding
,Game.Net.ServiceCoverage
,ResourceAvailability
,Density
. - Else if
!m_HighwayRules
, adds:ConnectedBuilding
. - (These components enable maintenance, condition tracking, zoning/adjacency and other edge-specific behaviors.)
- Adds:
- Else if the component set contains
Game.Net.Node
:- Adds:
Road
,UpdateFrame
,LandValue
,NodeColor
,NetCondition
,Game.Objects.Surface
. - (Node-related components for intersection behavior and surface data.)
- Adds:
- Else if the component set contains
NetCompositionData
:- Adds:
RoadComposition
. - (Used for composition/mesh/building of the net asset.)
- Adds:
This method determines which runtime ECS components the road entities will have depending on whether the entity represents an edge, a node, or part of net composition data. Modders should be aware that setting m_ZoneBlock or m_HighwayRules affects which adjacency/zoning components are attached to the edge archetype.
Usage Example
// Example: configure a RoadPrefab instance (e.g. in editor or during prefab setup)
public void ConfigureRoad(RoadPrefab prefab, ZoneBlockPrefab zoneBlock)
{
// classification & behavior
prefab.m_RoadType = RoadType.CityStreet; // example enum value
prefab.m_SpeedLimit = 50f;
prefab.m_TrafficLights = true;
prefab.m_HighwayRules = false;
// link zoning behavior to this road
prefab.m_ZoneBlock = zoneBlock;
}
// When the prefab is processed, GetDependencies will add the zoneBlock to required prefabs,
// GetPrefabComponents will ensure RoadData is present, and GetArchetypeComponents will
// add the appropriate ECS components (including ConnectedBuilding/SubBlock/etc. if zoneBlock was set).