Skip to content

Game.Prefabs.BuildingExtensionPrefab

Assembly:
Assembly-CSharp (typical Unity/game assembly; actual assembly name may vary in the project's build)

Namespace:
Game.Prefabs

Type:
public class

Base:
StaticObjectPrefab

Summary:
A prefab type used to define a building extension object in the ECS-based game world. This class extends StaticObjectPrefab and exposes data used when the prefab is converted to entities (archetype components and runtime components). It marks the prefab with a "Building" mod tag and registers component types required for building extensions (both high-level prefab-component requirements and low-level entity archetype components). This prefab is typically authored in assets and consumed during prefab-to-entity conversion or spawn logic in Cities: Skylines 2 modding.


Fields

  • public bool m_ExternalLot
    Flag indicating whether this extension should be considered part of an external lot. Mods can toggle this to influence placement rules or lot behavior when the extension is spawned.

  • public float3 m_Position
    Local position offset for the extension relative to its parent or spawn location. Uses Unity.Mathematics.float3.

  • public int2 m_OverrideLotSize
    Optional override for the lot size that this extension occupies. Uses Unity.Mathematics.int2 (x,y lot dimensions). If non-zero, this can replace the default lot footprint.

  • public float m_OverrideHeight
    Optional override for the extension height. When set (non-default), this value can override default building height behavior for this extension.

Properties

  • public override IEnumerable<string> modTags { get; }
    Yields the mod tags for this prefab. It returns all tags from the base StaticObjectPrefab and adds the "Building" tag. Modders can inspect this to filter or group prefabs; the presence of "Building" indicates this prefab is part of the building domain.

Constructors

  • public BuildingExtensionPrefab()
    Default public constructor (implicit if not defined). Prefab instances are generally created by the asset/prefab system; when created programmatically, default field values are used. Initialize or modify fields (m_ExternalLot, m_Position, m_OverrideLotSize, m_OverrideHeight) after construction as needed.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds runtime/component requirements used by the prefab conversion step. This implementation calls the base and then adds:
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite() These indicate that entities created from this prefab will require BuildingExtensionData and Effect components (read/write).

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds entity archetype components required when creating entity instances from this prefab. This implementation calls the base and then adds:

  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite() These archetype components represent the low-level ECS components that the spawned entity will contain (extension marker, spawn location info, visual color, enabled effect state, etc.).

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called during prefab/entity initialization. The current implementation calls base.LateInitialize and contains no additional logic here, but this is where mods could add finalization logic for the entity (e.g., setting component values, resolving references) after archetype creation.

Usage Example

// Example: configure a BuildingExtensionPrefab instance programmatically
var prefab = new Game.Prefabs.BuildingExtensionPrefab();

// Set whether this extension belongs to an external lot
prefab.m_ExternalLot = true;

// Position offset relative to parent
prefab.m_Position = new Unity.Mathematics.float3(0f, 0f, 0f);

// Override lot size (width, depth)
prefab.m_OverrideLotSize = new Unity.Mathematics.int2(3, 4);

// Override height (meters)
prefab.m_OverrideHeight = 12f;

// Inspect mod tags (will include "Building")
foreach (var tag in prefab.modTags)
{
    UnityEngine.Debug.Log(tag);
}

Notes for modders: - This class is intended to be used as a prefab asset (authoring-time) rather than frequently constructed at runtime. - The GetPrefabComponents / GetArchetypeComponents methods drive which ECS components are present on entities spawned from the prefab; modify these with care to remain compatible with systems expecting BuildingExtension-related components. - Because the class uses Unity.Entities types (EntityManager, Entity, ComponentType) and Unity.Mathematics types (float3, int2), ensure proper assembly references and using directives when interacting with or extending this prefab in mods.