The Procedural Content Generation Framework (PCG) is a toolset for creating your own procedural content and tools inside Unreal Engine. PCG provides technical artists, designers, and programmers with the ability to build fast, iterative tools and content of any complexity, ranging from Asset utilities, such as buildings or biome generation, up to entire worlds.
Important Concepts and Terms
- Points: Locations in 3D space that are generated by the PCG graph and are often used to spawn meshes. Points contain information about their transforms, bounds, color, density, steepness, and seed. They can be assigned user-defined attributes.
- Point Density: Value used by a variety of graph nodes. This is represented in the debug view as a gradient on each point. A density of 0 is black, and a density of 1 is white.
Required Setup
The Procedural Content Generation Framework requires the Procedural Content Generation Framework plugin to be enabled in your project. For more information on enabling plugins, see Working with Plugins.
The Procedural Content Generation Framework Geometry Script Interop plugin is required to sample points on Static Meshes.
The Procedural Node Graph
The Procedural Node Graph is the central piece of the Procedural Content Generation Framework.
Using a format similar to the Material Editor, spatial data flows into the graph from a PCG Component in your Level and is used to generate points. The points are filtered and modified through a series of nodes, with the output being updated in real time. The resulting points can be used to spawn a variety of Assets.
Create the PCG Graph Asset
To create a PCG Graph Asset, follow the steps below:
- Right click in the Content Drawer or Content Browser, navigate to Create Advanced Asset > PCG, and select PCG Graph.
- Choose a name for the new Asset and press Enter.
Editing the PCG Graph
Using the PCG Graph Editor, you can configure and edit your PCG Graph Assets. Navigating the editor is similar to the Blueprint or Material editor. It also contains some PCG specific tools and panels.
Number | Description |
---|---|
1 | Node Palette |
2 | Debug dropdown |
3 | Viewport |
4 | Details panel |
5 | Attributes list |
Similar to working with Blueprints, you can add nodes to the graph by dragging them into the viewport from the Node Palette or by using the context menu.
Changes made to a PCG Graph update in real time in the Editor viewport when the graph is connected to a PCG Component and has been used to generate content.
PCG Nodes
The PCG Graph is made of a series of PCG Nodes, each one performing an operation that contributes to the final result.
These nodes are divided into the following categories:
Category | Description |
---|---|
Blueprint | Contains Blueprint-related nodes. This includes the common node to execute user Blueprints derived from PCGBlueprintElement. |
Color | Contains nodes affecting color on points. |
Debug | Contains nodes that help with debugging. |
Density | Contains nodes that affect point density. |
Filter | Contains nodes that filter data based on criteria or per-point. |
IO | Contains nodes that control interaction with external data. |
Metadata | Contains nodes that interact with Attributes, whether on points or on Attribute Sets. |
Params | Contains nodes that control retrieval of parameters from Actors or Blueprint variables. |
Sampler | Contains nodes that generate points from a source of spatial data, such as volumes, surfaces, and meshes. |
Spatial | Contains nodes that create spatial relationships between data, change their internal spatial data, or retrieve data. |
Spawner | Contains nodes that create new data or place Actors at given point locations. |
Subgraph | Contains nodes that deal with using subgraphs. |
Transforms | Contains nodes that modify transform information on points. |
Like Blueprints, you can add Comments and Reroute Nodes to improve the readability of your graph.
PCG Component
PCG Component The Procedural Node Graph can sample your Level through the PCG Component. This component holds an instance of your Procedural Node Graph and manages the generation of procedural content, both in the Editor and at runtime. PCG components are added as a component to an Actor or used as part of the PCG Volume, a basic volume useful for quickly setting up procedural content.
To connect a PCG graph to your PCG component, follow the steps below:
- In the Editor viewport or Outliner, select the PCG Volume or Blueprint Class that you want to connect.
-
In the Details panel, click the PCG Component.
-
Click the Graph dropdown and select the PCG Node Graph you want to use.
-
Click the Generate button to see your result.
Debugging in PCG
Debugging is an essential part of the PCG workflow.
Each node has a variety of debug options that you can use to visualize the point data at each step of the PCG graph:
- Debug Rendering
- Enable / Disable node
- Inspect
Toggle Debug Rendering for each node by selecting the checkbox for Debug in the node's Details panel or by pressing the D key.
Toggle each node on and off by selecting the checkbox for Enabled in the node's Details panel or by pressing the E key.
You can also display all the points a node generates in the Attributes list by inspecting the node.
Select your PCG component from the Debug dropdown menu. Then, right-click the node you want to inspect in the viewport and select Inspect. Alternatively, you can press the A key.
Create a Simple Forest Volume
A common use case for procedural generation tools is biome generation in an open world environment.
To create a basic forest biome generator, follow the steps below.
This sample uses Materials and Static Meshes from the Megascans Trees: European Hornbeam collection downloaded using the Marketplace.
Create the Level
- Create a new Project in Unreal Engine.
- Create a new Level using the Basic level template. Save your Level.
- Delete the Floor Static Mesh and add a new Landscape to the level using Landscape mode.
-
Using the Sculpt tools, add some variation to your Landscape.
Create the PCG Volume
- Return to Selection Mode and enable the Place Actors window, if it's not currently visible.
-
Use the Search Classes box to find the PCG Volume and add one to your level.
- Scale the PCG Volume to X=8.0, Y=8.0, Z=8.0
Create the PCG Graph Asset
- Right click in the Content Drawer or Content Browser, navigate to Create Advanced Asset > PCG, and select PCG Graph.
- Name the new asset PCG_ForestGen and press Enter.
- Double-click PCG_ForestGen to open the PCG Graph Editor.
Connect the PCG Component
- In the Editor viewport or Outliner, select the PCG Volume.
- In the Details panel, click the PCG Component.
-
Click the Graph dropdown and select PCG_ForestGen from the list.
Create the Points
- In the PCG Graph Editor window, add a Surface Sampler node to the graph.
-
Click the down arrow on the Input node to expand it, then connect the Landscape output to the Surface input on the Surface Sampler.
- Select the Surface Sampler and press the D key to toggle Debug Rendering.
- Back in the Editor window, select the PCG Volume and click the Generate button in the Details panel.
You can now see the points being generated in the Editor viewport. The points conform to the shape of the Landscape.
Add Variation
- In the PCG Graph Editor, select the Surface Sampler.
- Add more points by adjusting the Points Per Square Meter, Points Extents, and Looseness properties in the Details panel.
- Adjust the Points Per Square Meter to 0.15 to add more points to the space.
- The Points Extends property controls the size of each point's bounds. Change the X, Y, and Z values to 50.
- The Looseness property determines how closely the generated points conform to a grid shape. Leave the Looseness value at 1.0.
-
Next, add a Transform Points node. This node adds additional movement, rotation, and scale changes to your points with a defined range. Connect the Output pin of the Surface Sampler node to the Input pin of the Transform Points node.
- Disable Debug Rendering on the Surface Sampler node and enable it on the Transform Points node.
-
To add some rotation variation, change the Z value for the Max Rotation to 360. This gives all the points a random rotation between 0 and 360 degrees.
- The PCG graph spawns points and rotates them to conform with the normal direction of the Landscape. Disable this extra rotation by selecting the checkbox for Absolute Rotation.
-
To add some size variation set the X, Y, and Z Scale Min values to 0.5. Change the X, Y, and Z Scale Max values to 1.2.
The end result is a set of points with a good amount of variation.
Spawn the Static Meshes
-
In the PCG Graph Editor, add a Static Mesh Spawner node to the graph viewport. Connect the Output pin of the Transform Points node to the Input pin of the Static Mesh Spawner.
- Select the Static Mesh Spawner.
- In the Details panel, locate the Mesh Entries option and click the + button to add a Static Mesh to spawn.
- Click the down arrow next to Mesh Entries to open the array.
- Click the down arrow next to Index [0].
- Click the down arrow next to Descriptor.
-
Click the dropdown menu for Static Mesh and select the tree that you want to spawn. This example uses SM_EuropeanHornbeam_Forest_01.
You can add additional Static Meshes and balance the variety using the Weight property for each mesh entry in the array. Unreal Engine adds the weight value of all the Static Mesh entries and divides that number by each individual weight to determine the probability of each entry spawning.