πŸ’ͺRuntime Scripting API

The TerraForge 2 Runtime Scripting API provides developers with powerful tools to control terrain generation and modifications programmatically. This API allows for runtime customization and automation, making it easier to integrate TerraForge 2 into dynamic environments. Below are the primary methods and examples for using the API.


Terrain Generation

Basic Terrain Generation

To generate terrain using the TerraForgeTerrainGenerator component:

using UnityEngine;
using TerraForge2.Scripts.Generators;

public class TestAPI_TerrainGenerate : MonoBehaviour
{
    // Reference to the TerraForge terrain generator
    public TerraForgeTerrainGenerator terrainGenerator;

    void Start()
    {
        // Initiates terrain generation
        terrainGenerator.TerrainGenerate();
    }
}

Runtime Island Generation Using Seed Switching

This example demonstrates how to use TerraForge 2 as a runtime island generator by reusing a predefined setup (biomes, terrain layers, painting, erosion settings) and generating a new island every time simply by switching the seed.

This is useful when:

  • You design an island setup once in the editor.

  • You want to generate different variations of that island at runtime (for example, for multiplayer sync or world randomization).

  • You want to avoid modifying the original TerrainData from your prefab.

Saving Parameters with PlayerPrefs

To save the parameters of the TerraForgeTerrainGenerator component after generating terrain:

Loading Saved Parameters with PlayerPrefs

To load previously saved parameters before generating terrain:

Tracking Terrain Generation Completion

To track when the terrain generation process is complete:

Applying LayerSettingsData

Example of loading LayerSettingsData

Here is an example of loading and applying LayerSettingsData to TerrainPainter:

Applying Biome Settings

Applying Biome Settings to a Terrain Generator

To apply specific biome settings to the TerraForgeTerrainGenerator:

Modifying Generation Parameters

Changing Generation Parameters of the Terrain Generator

To change the generation parameters dynamically:

Advanced Terrain Generation

Creating a New TerrainData File

To create a new TerrainData file and generate terrain:

Changing Terrain Resolution

To change the resolution of the terrain:

Generating a Terrains Grid with Custom Parameters

To generate a grid of terrains with custom parameters:

These are just examples of usage. You can create your own unique methods and ways of using the API. The demo scenes also partially utilize the above methods.

Last updated