Skip to content

Game.Prefabs.TerrainArea

Assembly: Assembly-CSharp (game or mod assembly — actual assembly may vary by build)
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
TerrainArea is a prefab component used to configure procedural terrain adjustments for an area. It exposes inspector-editable parameters (height offset, slope width, noise scale/factor and absolute-height flag) and writes those values into a TerrainAreaData ECS component during prefab initialization. The class is annotated with a ComponentMenu attribute so it appears in the editor under "Areas/".


Fields

  • public float m_HeightOffset = 20f
    Used to offset the base terrain height for the area. This value is copied to TerrainAreaData.m_HeightOffset during initialization.

  • public float m_SlopeWidth = 20f
    Controls the width of the sloped transition region applied to the terrain. Copied to TerrainAreaData.m_SlopeWidth.

  • public float m_NoiseScale = 100f
    Inspector value representing noise scale; during initialization this is converted to an inverse scale (1 / max(0.001f, m_NoiseScale)) and stored into TerrainAreaData.m_NoiseScale. This guards against division by zero and excessively large inverse values.

  • public float m_NoiseFactor = 1f
    Multiplier applied to procedural noise when shaping terrain; copied to TerrainAreaData.m_NoiseFactor.

  • public bool m_AbsoluteHeight
    Flag indicating whether m_HeightOffset should be treated as an absolute world height (true) or as a relative offset (false). Stored in TerrainAreaData.m_AbsoluteHeight as 1.0f for true and 0.0f for false.

Properties

  • (none)
    This class does not define C# properties; it uses public fields for inspector exposure and overrides methods from ComponentBase.

Constructors

  • public TerrainArea()
    Implicit default constructor. No custom construction logic in the class; setup is performed in Initialize.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() to the provided set so the prefab will include the TerrainAreaData component on created entities.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() to the provided set. This ensures entities created with this prefab include the Terrain component in their archetype.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is instantiated into an ECS Entity. Creates a TerrainAreaData struct, copies/derives values from the inspector fields:

  • m_HeightOffset <= m_HeightOffset
  • m_SlopeWidth <= m_SlopeWidth
  • m_NoiseScale <= 1f / math.max(0.001f, m_NoiseScale)
  • m_NoiseFactor <= m_NoiseFactor
  • m_AbsoluteHeight <= (m_AbsoluteHeight ? 1f : 0f) and writes that struct into the entity via entityManager.SetComponentData(entity, componentData).

Usage Example

// Example: configure the prefab in the inspector (or by script) and let Initialize write ECS component data.
// No additional calls are required; the engine calls Initialize when converting the prefab to an entity.

TerrainArea terrainArea = gameObject.GetComponent<TerrainArea>();
terrainArea.m_HeightOffset = 15f;
terrainArea.m_SlopeWidth = 10f;
terrainArea.m_NoiseScale = 50f;
terrainArea.m_NoiseFactor = 0.8f;
terrainArea.m_AbsoluteHeight = true;

// When the prefab is converted to an Entity, Initialize(...) will be invoked and TerrainAreaData will be set
// with the transformed/validated values (note: m_NoiseScale is inverted internally).

Notes and tips: - The class relies on TerrainAreaData and Terrain ECS components; ensure those component types exist in the project. - The m_NoiseScale field is stored as an inverse scale in the ECS data to avoid division in hot code paths; do not expect the stored value to equal the inspector number. - m_AbsoluteHeight is stored as a float (1 or 0) in the TerrainAreaData struct, so other systems read it as numeric rather than a bool.