CWorldSpawner

Overview

ACWorldSpawner is the main actor to place in a level. It inherits from ACAbstractSpawner and implements ICWorldData. It reads its configuration from a DataTable row, instantiates the worldmaker and drives the generation loop on tick.

Properties

Name Description
worldMakerRH FDataTableRowHandle pointing to a FCWorldSpawnerDataStruct row
pawnToTrack Pawn whose location drives tile generation. If null, generates at origin then stops
worldmaker Transient reference to the instantiated UCAbstractWorldmaker
worldNoise Transient reference to the world UCNoisator singleton

Lifecycle

Name Description
init Reads the DataTable row, creates the world noisator singleton, instantiates the worldmaker
Tick Calls worldmaker->buildASync with the tracked pawn position. Stops ticking if no pawn and world is built
clean Destroys the worldmaker and its resources
debug Toggles debug material on all generated tiles (CallInEditor)
// ACWorldSpawner is placed in the level.
// Configure worldMakerRH to point to a DataTable row of type FCWorldSpawnerDataStruct.
// Assign pawnToTrack to the player pawn or any pawn to follow.

// init() is called by the spawner system (ACAbstractSpawner).
// It creates the UCNoisator singleton and instantiates the worldmaker:
UCNoisator::instanciate(GetRootComponent()->GetOwner(),
    CSingletonName::CNAME_Singleton_WorldNoise,
    worldNoise, seed,
    data->worldNoiseDataAsset->fastNoiseStruct,
    data->worldNoiseDataAsset->noiseStructArray);

UCAbstractWorldmaker::instantiate<UCAbstractWorldmaker>(
    GetRootComponent(),
    data->worldMakerStruct.worldMakerClass,
    worldmaker, stream,
    data->worldMakerStruct);

// On Tick, the spawner delegates to the worldmaker:
worldmaker->buildASync(this,
    pawnToTrack->GetActorLocation().X,
    pawnToTrack->GetActorLocation().Y);

ICWorldData interface

ACWorldSpawner implements ICWorldData, making world queries available globally via WorldUtility static functions.

Name Description
zCalculate Returns the Z height at (x,y) with vertex color output
calcMax4PointSlope Computes slope from 4 surrounding sample points
bendRotatorOnSlope Adapts a rotator to align with the terrain slope
worldExists Returns true if a worldmaker is instantiated
worldReady Returns true if the world noise is initialized and ready for Z queries
worldBuilt Returns true if all tiles have been generated
worldTileReadyAt Checks if the tile at (x,y) is rendered, outputs UV index and full LOD status
boundToOnTileReady Binds an ICWorldBoundable to receive onTileReady / onTileRemoved delegates
unboundToOnTileReady Unbinds an ICWorldBoundable from tile delegates
// Any system can query the world via WorldUtility static functions:
float z = WorldUtility::zCalculate(x, y);
FVector z3D = FVector(x, y, WorldUtility::zCalculate(x, y));

// Check if world is ready for queries:
if (WorldUtility::worldReady()) { /* safe to call zCalculate */ }

// Check if a specific tile is rendered:
FCUVIndex uvIndex;
bool fullLOD;
if (WorldUtility::worldTileReadyAt(x, y, uvIndex, fullLOD)) {
    // tile at (x,y) is rendered, fullLOD indicates max detail
}

// Bind to tile events:
WorldUtility::boundToOnTileReady(myWorldBoundableObject);