The Procedural Content Generation Framework (PCG) is a toolset for creating your own procedural content and tools inside Unreal Engine for Fortnite (UEFN). 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: A value stored on each point, usually from 0 to 1. When points are sampled, the density is the highest value of the density function inside the point's volume. Many nodes also use density as a weight, for example when filtering points against a threshold. In the debug view, density appears as a gradient on each point.
Splines and Areas: An open spline describes a path; a closed outline can describe a filled area. Choose the form the next operation needs.
Datasets: Groups of data. Ten points in one group are different from ten separate groups; some operations work once per group.
Attributes and Tags: An attribute stores a value, such as height or distance. A tag labels a dataset so you can find it later.
Bounds: The space data occupies. Bounds-based fitting and overlap checks are not exact mesh collision tests.
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 Procedural > PCG, and select PCG Graph.
Choose a name for the new asset and press Enter.
In the Create Graph From Template window, select Create empty graph to start from a blank graph, or select a template and click Initialize From Template. The window appears only when at least one graph in the project is marked as a template.
PCG Graph Templates
After creating a PCG graph, you can mark the graph as a template, which can then be selected from the context menu when creating new graphs. Similar to Niagara templates, you can expedite your workflow using a PCG graph template rather than starting from a blank graph.
Set a PCG Graph as a Template
To define a PCG graph as a template, open the graph and use the following steps:
In the Tool Bar, click the Graph Settings button to populate the Details panel with the graph settings.
Navigate to the Asset Info section of the Details panel and enable the Is Template property.
Your graph is now defined as a Template Graph.
Creating a New Graph using a Template
When creating a new graph, after you choose the asset name and location, you can now select a graph template from the Create Graph From Template window. Select the graph template you want to use, then click Initialize From Template to create a new graph using the template.
To disable the template prompt when creating new PCG Graphs, navigate in the menu bar to Edit > Editor Preferences. Then use the search bar or navigate to the PCG Editor section of properties and disable the Show Template Picker on New Graph property.
When this property is disabled the Create Graph From Template window will not appear when creating new PCG Graphs.
Editing the PCG Graph
Using the PCG Graph Editor, you can configure and edit your PCG Graph Assets. Navigating the editor is similar to other node-based editors, such as the Material Editor. It also contains some PCG specific tools and panels.
| Number | Description |
|---|---|
1 | Toolbar |
2 | Palette |
3 | Viewport |
4 | Details |
5 | Debug Object |
6 | Attributes |
You can add nodes to the graph by dragging them into the viewport from the 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 assigned to a PCG component and is used to generate content.
Find, Profiling, and Graph Parameters open by default. More tabs, such as Log, Determinism, and Data Overrides, open from the Window menu.
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:
Control Flow | Contains nodes for controlling the flow of logic through the graph. |
Data Layers | Contains nodes that read World Partition Data Layers from actors and partition data by them. To assign Data Layers to spawned actors, use the Spawn Actor or Create Target Actor node. |
Debug | Contains nodes that help with debugging. |
Density | Contains nodes that affect point density. |
Dynamic Mesh | Contains nodes that create and edit dynamic meshes. |
Filter | Contains nodes that filter data based on criteria or per-point. |
Generic | Contains nodes that affect data, but not spatial data. |
GPU | Contains nodes that run on the GPU, such as Custom HLSL, Download From GPU, and Generate Landscape Textures. |
Graph Parameters | Contains nodes that read graph parameters. |
Hierarchical Generation | Contains nodes for controlling the Hierarchical Generation mode. |
Input Output | Contains nodes that read and write external data, such as Load PCG Data Asset. |
Metadata | Contains nodes that interact with attributes, whether on points or on Attribute Sets. |
Param | Contains nodes that control retrieval of parameters from actors, such as Get Actor Property. |
Point Ops | Contains nodes that affect points and their properties. |
Reroute | Contains reroute nodes for organizing connections in the graph. |
Resource | Contains nodes that load and manage external resources. |
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. Includes a library of ready-made PCG Primitives subgraphs, such as Place_RadialScatter, Spawn_Assets, and Fill_Areas_Randomly, that you can use with the Subgraph node. |
UEFN has nodes that work with Scene Graph entities (Get Entity Data, Create Target Entity, and Add Static Mesh Entities) and the Execute Python Script, Python Data Processor, Get Landscape Grass Types, Find Concave Hull 2D, Find Closest Point On Spline, and Trapezoidal Decomposition nodes.
You can add Comments and Reroute Nodes to improve the readability of your graph.
Graph Editing Customization
You can customize editing PCG graphs using a dedicated set of properties that you can access in the Graph Settings panel.
With these properties, you can customize your PCG graph’s behavior and workflow for a more curated experience. You can then use these settings to build PCG Graph Templates which can tailor your PCG graph workflow for your project.
Node Filtering
You can use the Node Filter settings to filter node selections by category. In the Graph Settings, expand Customization > Graph Customization, enable the Filter Nodes by Category property, and set Node Filter Type to Allow or Disallow. Then add an index to the Filtered Categories property using the Add (+) button. After adding an Index you can then type the category name in the text field, or use the drop-down menu to select a node category.
Changing the filters will update the selection available from the node palette and also from the contextual menu.
Graph Filtering
In addition to filtering the available nodes, you can filter the available subgraphs. Enable the Filter Subgraphs property, set Subgraph Filter Type to Allow or Disallow, then click Add (+) under Filtered Subgraph Types and select a subgraph. You can filter nodes by their settings class in the same way with Filter Settings, Settings Filter Type, and Filtered Settings Types.
Attributes and Metadata
Attributes are similar to variables and store data defined by its name and type. There are two types of Attributes:
Static Attributes: Attributes that are fixed and always present. These start with a
$, such as$Position.$Indexis also available, and$NumElementscan be read from the Data domain as@Data.$NumElements.Dynamic Attributes: Attributes that are created at runtime, and stored as part of the Metadata of the graph data.
In the Attribute Selector menu, static attributes are listed under Properties and dynamic attributes under Attributes.
Metadata Domains
When using Attributes in PCG Graphs, you must consider the Domain the Metadata exists in. The domain will control what kind of information you can save as well as how it can be used and manipulated later. For each metadata point must know which domain is supported, and which domain is the default. Domains are prefixed by @ when selecting them.
The attribute list view has a field to switch between domains.
There are two domains:
The Data domain holds attributes that belong to the data as a whole, such as the transform of a spline. It can only have a single entry, and does not support multi-entries like the Elements domain.
You work with it like any other domain; create attributes, or write to them with metadata operations, by prefixing the attribute name with
@Data. For example, an attributeMyAttrin the Data domain is@Data.MyAttr. The Data domain is the default for spatial data that is not made of points, splines, or polygons.The Elements domain holds one value for each element. Its prefix depends on the type of data:
@Pointsfor point data.@ControlPointsfor the control points of a spline.@Verticesfor polygons.@Elementsfor attribute sets.
The Elements domain is the default for point data, attribute sets, polygons, and spline metadata.
If you don't specify a domain, PCG uses the default domain for that type of data.
Attribute Selector
Some PCG graph nodes can be used to provide interoperability between static attributes and dynamic attributes through the Attribute Selector.
The Attribute Selector provides you with a list of attributes that are available to use with the selected node. The Attribute Selector uses the following naming rules:
Names starting with a
$are static attributes, while names without are dynamic attributes.@Lastrepresents the last dynamic attribute written to by the previous node.@Source, used in output selectors, means the same attribute as the input.
For example, the Math node is used to perform mathematical operations on static and dynamic attributes:
You can also use the Attribute Selector name field to extract data from components:
In the image above, $Position.ZYX provides the inverse of the components of $Position. Components can be combined in any order, such as XY or ZYX. Below are the components that can be manipulated in this way and their types:
| Component | Type |
|---|---|
| Vectors | |
X, Y, Z, W, x, y, z, w | Double. Can’t be mixed with RGBA. |
R, G, B, A, r, g, b, a | Double. Can’t be mixed with XYZW. |
Length, Size, SquaredLength | Double. Returns the vector length or squared length. |
Normalized | Vector. Returns the normalized vector. |
| Transforms | |
Location | Vector3 |
Scale | Vector3 |
Rotation | Quaternion |
| Rotators | |
Pitch, Yaw, Roll | Double |
Forward, Right, Up | Vector3 |
EulerAngles | Vector3 |
| Quaternions | |
Support Vector extractor | Vector |
Support Rotator extractor | Rotator |
| Strings | |
Length | Number of characters in the string. |
Settings Overrides
Some node settings are overridable.
To override a node manually, click the arrow at the bottom of the node to expose the advanced pins that are normally hidden. There are two types of pins:
Global override (the Overrides pin): Accepts any number of attributes and overrides every setting whose name exactly matches an attribute name. If several settings share a name, use the full property path. Only the first attribute set connected to the pin and its first entry is used, unless the override is an array.
Single override: Accepts any number of attributes and overrides the specific setting if an attribute is found with an exact match with the setting name, or any name if there is only one attribute. If nothing is connected to the single override pin, the Overrides pin is used.
Attribute types need to match but some types can be converted.
To know the exact name or type, use the tooltip on the override pin:
Spline Metadata Example
The following sections will provide some example setups of practical PCG Metadata workflows.
Spline Attributes
Using attributes, you can read and write control point properties directly. You can access the following list of properties using Add (+) > Spline > Control Points.
| Name | Description | Type |
|---|---|---|
| Location component of the control point's transform (in world referential) | Vector |
| Rotation component of the control point's transform (in world referential) | Quaternion |
| Scale component of the control point's transform (in world referential) | Vector |
| World transform of the control point | Transform |
| Arrive Tangent at the control point | Vector |
| Leave Tangent at the control point | Vector |
| Type of interpolation at the control point for position (same as set on the spline control point) | ESplinePointType |
| Location component of the control point's transform (in spline referential) | Vector |
| Rotation component of the control point's transform (in spline referential) | Quaternion |
| Scale component of the control point's transform (in spline referential) | Vector |
| Local transform of the control point | Transform |
Spline Data
You can also work with the spline's data properties directly. You can access the following list of properties using Add (+) > Spline > Global. Only $SplineTransform can be written; the other properties are read-only.
| Name | Description | Type |
|---|---|---|
| Transform of the spline (Read/Write) | FTransform |
| If the spline is closed or not (Read Only) | bool |
| Length of the spline (Read Only) | double |
Spline Metadata
On top of control point properties, you can add attributes to the control points of a spline. This metadata is interpolated when the spline is sampled, and behaves the same as point or attribute set metadata.
Similar to points, you can use Add Attribute to create a new attribute, or use the metadata operations and specify a given output target to write into this attribute.
In addition, metadata on control points is the default for spline metadata, but you can also be explicit with @ControlPoints.
Polygon Metadata
Vertices domain
| Name | Description | Type |
|---|---|---|
| Location of the vertex in world coordinates. (Read/Write) | Vector |
| Rotation of the vertex in world coordinates. (Read only) | Quaternion |
| Segment index of the vertex in the current polygon (outer or hole) (Read only) | int |
| Index of the hole the vertex is inside of. -1 on the Outer polygon. (Read only) | int |
| Length of the segment starting from the vertex. (Read only) | double |
| Location of the vertex in 2d coordinates. (Read/Write) | Vector2D |
| Rotation of the vertex in 2d coordinates. (Read only) | Quaternion |
Data domain
| Name | Description | Type |
|---|---|---|
| Transform of the 2d polygon. (Read/Write) | Transform |
| Area of the 2d polygon. (Read only) | double |
| Perimeter of the 2d polygon. (Read only) | double |
| Minimum point of the bounds of the 2d polygon in 2d space. (Read only) | Vector2D |
| Maximum point of the bounds of the 2d polygon in 2d space. (Read only) | Vector2D |
| Number of segments in the 2d polygon, including hole segments. (Read only) | int |
| Number of segments in the outer polygon only. (Read only) | int |
| Number of holes in the 2d polygon. (Read only) | int |
| Index of the longest segment in the outer polygon. (Read only) | int |
| Whether the 2d polygon is clockwise or counter-clockwise. (Read only) | bool |
Graph Parameters
Similar to parameters in the Material editor, PCG Graph Parameters are user created overridable values and can help create customizable graphs for a variety of situations. To create a new parameter:
Access the Graph Parameters tab. If it is closed, click Open Graph Parameters in the Graph Settings.
Click the + button. This creates a new parameter of type Double.
Open the menu next to the new parameter. Rename it and change the type if needed.
To change the value of a parameter on a PCG Graph:
Change the value in the graph parameters or in the Details panel of a PCG asset.
To change the value of a parameter on a PCG graph instance:
Open the asset in the Content Browser and change the value or in the Details panel of a PCG asset.
Graph Instances
PCG graph instances work similar to material instances and use graph parameters to help you reuse your existing graphs as instances or PCG subgraphs:
To create a PCG graph instance, right-click a PCG graph asset in the Content Browser and select Create PCG Graph Instance.
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.
Use the PCG Volume Lite, a basic volume useful for quickly setting up procedural content, to add a PCG Component Lite to your level. UEFN has no Verse API for PCG, it is editor only.
To connect a PCG graph to your PCG component, follow the steps below:
In the Editor viewport or Outliner, select the PCG Volume Lite or other actor that has the PCG Component 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.
The PCG component also controls how it generates. Seed changes the random result, and Is Partitioned controls how the generated content is stored. The Generate, Cancel, Cleanup, and Clear PCG Link buttons give you a way to manage the generated content directly; hold Ctrl and click Generate to force generation.
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 in the Debug Object tree.
Select the node you want to inspect.
Press the A key to toggle inspection. You can also double-click the node.
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.
Create the Level
Create a new project in UEFN.
Create a new Level using the Survival Island level template. Save your Level.
As an option, you can use the Landscape Sculpt tools to change the default 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 Lite and add one to your level.
Scale the PCG Volume Lite 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 Procedural, and select PCG Graph. If the Create Graph From Template window appears, select Create empty 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 Lite.
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 Get Landscape Data node to the graph.
Drag from the output of Get Landscape Data and add a Surface Sampler node.
Select the Surface Sampler and press the D key to toggle Debug Rendering.
In the editor window, select the PCG Volume Lite 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 window, select the Surface Sampler.
Add more points by adjusting the Points Per Squared Meter, Point Extents, and Looseness properties in the Details panel.
Adjust the Points Per Squared Meter to 0.15 to add more points to the space.
The Point Extents property controls the size of each point's bounds. Make sure the X, Y, and Z values are 50 (the default).
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 Rotation Max 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 window, add a Static Mesh Spawner node to the graph. 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 inside the Mesh Selector, 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 OakLarge01.
You can add more Static Meshes and balance the variety using the Weight property of each mesh entry. The chance of an entry spawning is its weight divided by the total of all weights. For example, with weights of 3 and 1, the first mesh spawns about three times as often as the second.
Trees in UEFN are large, so the result can look crowded. Lower the value of Points Per Squared Meter on the Surface Sampler node to space the trees out, or change the Seed on the PCG Volume Lite in the level to get a different layout.