Skip to main content

Generation Callbacks

The purpose of GenerationCallbacks is to perform custom logic on a Path's spawned component during different phases of Path generation. Callbacks can for example abort spawning of a component or change its properties (eg: transform, appearance).

GenerationCallbacks can be run at different stages:

  • "PreSpawn" - right before spawning of a component
  • "PostSpawn" - right after spawning of a component
  • "PreLandscapeAdjustment" - before we start the landscape & biomes adjustment
  • "PostLandscapeAdjustment" - after the landscape & biomes adjustment has finished

A single callback can execute logic in one or multiple stages and can be implemented in code or in Blueprints.

GenerationCallbacks can be set for the PathTemplate's Static/Spline Meshes and Decal Components:

image

And can also be configured in PathDescription and are then applied to all the components spawned by the Path:

image

Creating a new GenerationCallback

As an example, we will create a new GenerationCallback that changes the color of a mesh.

  1. We first create a GenerationCallback asset.
  1. Override the "PostSpawn" function, then save and compile the blueprint.
  1. Create and open a new material.
  1. Add color parameter, set the "Use Custom Primitive Data" to true, then save and apply changes.
  1. Open a Path's PathTemplate.
  1. Add a cube mesh and place it somewhere.
  1. Assign the material and add the GenerationCallback.
  1. Lastly, compile the PathTemplate and regenerate the Path.
note

For simplicity, in this test we disabled converting meshes to instances by setting Path's "Convert Path Components to Instances" property to false. Supporting instancing would make the material more complex.

Labels in GenerationCallbacks

GenerationCallbacks can sample Path Labels and perform certain logic only when certain Labels are fullfilled.

image

warning

Do not use functions from the "Label Library" in GenerationCallbacks as they won't work properly (are meant for logic inside of Path Labels). Use functions from "Errant Paths Blueprint Function Library".

As an example, we will create a GenerationCallback that assigns a random color to meshes where a "RandColor" Path Label is fulfilled.

image

We paint the Path Label manually, for simplicity, and can observe how boxes underneath change their color.

info

The plugin automatically detects which Path Labels were used by GenerationCallback blueprint graphs and makes sure these Labels are calculated during Path generation. However, when implementing GenerationCallbacks in C++ code, you need to manually fill the NestedLabels property with Labels that you sample (see the UEpToggleRVTGenerationCallback as an example).

Examples

The plugin comes with a few examples of GenerationCallbacks that you can inherit from when creating your own callbacks. The base classes in these examples are implemented in code, for better performance. Then we have BPs that inherit these base classes and allow for adjusting their parameters.

GenerationCallbacksExamples.png

1. Spawn only over the snow weightmap

This GenerationCallback inherits from the UEpIsComponentAtWeightmap which checks whether the given weightmap (set in the class settings) is above/below a component. If it is, the component is spawned.

GenerationCallbacksExamples.png

2. Spawn only in the blocking volume

This GenerationCallback inherits from the UEpIsComponentNearVolume which checks whether a volume of the given class (set in the class settings) is close enough. If it is, the component is spawned.

GenerationCallbacksExamples.png

3. Project onto the landscape

This GenerationCallback inherits from the UEpProjectComponentOntoGeometry which projects a component on the given geometry (set in the class settings)

GenerationCallbacksExamples.png