Skip to content

Game.Prefabs.BuildingTerraformOverride

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
BuildingTerraformOverride is a prefab component used by building prefabs to control how the surrounding terrain is leveled and smoothed when the building is placed. It exposes per-corner and per-area offsets for leveling and smoothing, overall height offsets, and an array of additional sub-lots (SubLot) to define extra smoothing/terraforming areas. At prefab initialization it adds the appropriate ECS components (BuildingTerraformData and, optionally, AdditionalBuildingTerraformElement buffer) and, for building extension prefabs, it will request a Lot archetype component. This is intended for modders to configure building-related terraforming behavior via prefab data (or by code when creating prefabs programmatically).


Fields

  • public SubLot[] m_AdditionalSmoothAreas
    Array of SubLot entries that define extra smoothing/terraform areas around the building. When non-empty, the prefab initialization writes these into a DynamicBuffer on the created entity.

  • public float2 m_LevelMinOffset
    Minimum X/Z offset for level operations (used by building leveling logic).

  • public float2 m_LevelMaxOffset
    Maximum X/Z offset for level operations.

  • public float2 m_LevelFrontLeft = new float2(1f, 1f)
    Per-corner level offset for the front-left corner (X/Z). Similar fields exist for other corners.

  • public float2 m_LevelFrontRight = new float2(1f, 1f)
    Per-corner level offset for the front-right corner (X/Z).

  • public float2 m_LevelBackLeft = new float2(1f, 1f)
    Per-corner level offset for the back-left corner (X/Z).

  • public float2 m_LevelBackRight = new float2(1f, 1f)
    Per-corner level offset for the back-right corner (X/Z).

  • public float2 m_SmoothMinOffset
    Minimum X/Z offset used by smoothing operations.

  • public float2 m_SmoothMaxOffset
    Maximum X/Z offset used by smoothing operations.

  • public float m_HeightOffset
    Global height offset applied to the building's base terraforming.

  • public bool m_DontRaise
    If true, prevents automatic raising of terrain for this prefab.

  • public bool m_DontLower
    If true, prevents automatic lowering of terrain for this prefab.

  • public class SubLot (nested)
    A helper nested class describing an extra smoothing/terraform area. See SubLot fields below.

SubLot fields: - public Bounds2 m_Area = new Bounds2(-4f, 4f)
Rectangular area (2D bounds) of the sub-lot, defaulting to -4..4.

  • public float m_HeightOffset
    Height offset to apply inside this sub-lot.

  • public bool m_Circular
    If true, treat the area as circular rather than rectangular.

  • public bool m_DontRaise
    If true, do not raise terrain inside this sub-lot.

  • public bool m_DontLower
    If true, do not lower terrain inside this sub-lot.


Properties

This component does not declare any C# properties beyond the public fields. Its behavior is expressed via the public fields and overridden methods that register ECS components.


Constructors

  • public BuildingTerraformOverride()
    Default parameterless constructor (implicit). The class is intended to be configured in prefab data (inspector or prefab asset) rather than constructed and configured at runtime via code; no custom construction logic is provided.

Methods

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype components required by this prefab type. Behavior:
  • If this prefab's base prefab (base.prefab) is a BuildingExtensionPrefab, the method requests a Lot component (ComponentType.ReadWrite), which signals that entities of this prefab should include Lot data in their archetype.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers ECS components that must be present on entities created from this prefab. Behavior:

  • Always adds ComponentType.ReadWrite() so runtime systems can read building terraforming parameters.
  • If m_AdditionalSmoothAreas is non-null and has elements, also adds ComponentType.ReadWrite() so a dynamic buffer can be created to hold the extra areas.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab entity is created to write data into ECS storage. Behavior:

  • If m_AdditionalSmoothAreas contains entries, it obtains the DynamicBuffer for the entity, resizes it to match the array length, and copies each SubLot into the buffer as an AdditionalBuildingTerraformElement (mapping m_Area, m_HeightOffset, m_Circular, m_DontRaise, m_DontLower).
  • Note: BuildingTerraformData is registered via GetPrefabComponents but the class does not directly populate it here — that may be handled elsewhere or by other initialization code.

Usage Example

// Typical usage: configure this component on a building prefab (in editor or via prefab creation).
// At runtime, when the prefab entity is created, Initialize will copy additional smooth areas
// into an AdditionalBuildingTerraformElement DynamicBuffer so terraforming systems can use them.

[ComponentMenu("Buildings/", new Type[] { typeof(StaticObjectPrefab) })]
public class MyBuildingPrefab : BuildingPrefab
{
    // In the inspector, add a BuildingTerraformOverride component and set:
    // - corner level offsets (m_LevelFrontLeft/m_LevelFrontRight/...)
    // - m_SmoothMinOffset / m_SmoothMaxOffset
    // - m_AdditionalSmoothAreas (array of SubLot) if extra smoothing areas are needed
    //
    // No manual code required — Initialize() of BuildingTerraformOverride will handle writing
    // the AdditionalBuildingTerraformElement buffer when the entity is instantiated.
}