The Procedural Content Generation Framework (PCG) is a toolset for creating your own procedural content and tools inside Unreal Engine. The framework contains several PCG generation modes to facilitate the creation of larger worlds using PCG. Generation modes split the generation domain of a PCG Component into a grid, with each cell containing its own local PCG component.
PCG forest example spawning trees, grass, and other ground cover on a slope.
On a large grid, you can generate large, visually prominent meshes, such as trees and boulders. On a small grid, you can create smaller details, such as grass, flowers, and stones. This approach provides more granular control over the execution of PCG tools and is used to fine-tune the performance of tools that cover a large area.
There are four PCG generation modes:
- Non-partitioned Generation (default)
- Partitioned Generation
- Hierarchical Generation
Using Partitioned Generation
By default, all meshes generated by a PCG component are contained within the component’s domain, such as a volume or tied to a spline. This mode works for smaller PCG assets but can cause performance issues for assets that cover a large area. Partitioned Generation generates the resulting meshes across a user-defined grid. The data is split between each cell, making it easier to stream using other systems, such as World Partition and Level Instancing.
An example of a partitioned PCG component.
Enable Partitioning in the Graph
To toggle Partitioned Generation on a PCG component:
Toggling PCG Partitioned Generation in the PCG Volume Details panel.
- Select the PCG asset in your level.
- Click the checkbox next to Is Partitioned in the Details panel.
Configure the Partition Grid Size
The size of the partition grid is defined by the Partition Grid Size option on the PCGWorldActor:
Configure the Partition Grid Size option on the PCGWorldActor.
To configure the grid size:
- Select the PCGWorldActor in the Outliner.
- Adjust the value of the Partition Grid Size option.
- Select each PCG asset in your level and click Cleanup in the Details panel.
- Click the Generate button to regenerate the result.
Using Hierarchical Generation
Hierarchical Generation supports mesh generation using PCG at multiple scales. This type of generation overrides the Partition Grid Size used in Partitioned Generation using the Grid Size node and gives you the ability to fine-tune your mesh generation.
Example showing highlighted rocks generated on a smaller grid size.
The Grid Size node customizes the size of the generation grid for all data generated downstream of it and should be placed before any sampler nodes.
Enable Hierarchical Generation in the Graph
To enable Hierarchical Generation in your PCG graph:
Toggling PCG Hierarchical Generation in the PCG Graph Settings.
- Open your PCG graph and click the Graph Settings.
- Click the checkbox next to Use Hierarchical Generation.
- Open the dropdown box for HiGen Default Grid Size and select a value.
- Save your PCG graph.
Hierarchical Generation requires that your PCG components are partitioned. Make sure Partitioned Generation is enabled in your level before using this feature.
Configure Grid Size Settings
Use the Grid Size node to customize the generation of your meshes in the PCG Graph:
Setting the Hierarchical Generation grid size using the Grid Size node.
- Search for and add the Grid Size node before the sampler node in each branch of your PCG graph where you want to override the default hierarchical generation grid size.
- Click the Grid Size node and adjust the HiGen Grid Size setting.
- Save the graph.
- Regenerate your result in your level.
Use the size of your mesh to help determine the appropriate grid size in the graph. Large meshes are often less numerous than smaller meshes and should be placed on a larger grid to facilitate streaming. Smaller meshes are more numerous and should be placed on a smaller grid size.
Hierarchical Generation uses the following execution guidelines:
- Nodes that do not follow a Grid Size node in your PCG graph will generate data using the value defined in the HiGen Default Grid Size setting.
- Data generated on a larger grid size is available as cached data during the execution of a smaller grid. It cascades down a graph from larger grid size to smaller grid size but does not go from a smaller grid to a larger grid.
- If a node has multiple inputs using data from multiple grid sizes, the output is generated using the smallest grid size.
Using the Unbounded Grid Size
In the example below, a Mesh Sampler node is sampling a boulder mesh across a PCG volume:
Example showing the use of the Unbound grid size
The sampler samples the volume contents at the HiGen Default Grid Size and runs the performance-intensive operation four times, one for each grid cell in the volume. With this graph setup, performance worsens as the volume size increases.
For situations like this, it is recommended to use the Unbounded grid size. Unbounded removes the grid restriction for the PCG component and will execute nodes using this grid size once. Then, grid restrictions can be applied using the Grid Size node.
PCG subgraphs have their grid sizes disabled and use the grid size of their input data or parent graph.
It is possible to generate duplicate point data when passing data from a larger grid to a smaller grid. This occurs when data generated for a larger grid is replicated in every grid cell of a smaller grid and will significantly impact performance. You can remove the duplicate data by using the Cull Points Outside Actor Bounds node to remove the points from the point data that exists outside the smaller grid cell.
Visualizing Grid Size in the PCG Graph
Use the Debug dropdown menu to visualize the grid size used by each node in the PCG graph.
To visualize the grid size in the PCG graph:
- Open the Debug dropdown menu.
- Select a local PCG component. Each component name contains the grid size. For example,
PCGPartitionActor_12800_1_5_0/PCGComponent_1/NewPCGGraphis part of the 12800 cm grid.
Example showing the visualization of the Hierarchical Generation grid size.
In the above example, a component spawning rock meshes is selected (1). The nodes that spawn tree meshes (2) are highlighted but grayed out, showing that these nodes are spawning trees on a larger grid size and will execute before the rock nodes. The nodes in the bottom row are spawning grass meshes (3) and are grayed out, showing that they are spawning meshes on a smaller grid level and will not execute until after the rock nodes.