Introduction to PCG in Unreal Engine
- Lotta-Li Alftberg
- 4 dec. 2023
- 3 min läsning
Uppdaterat: 11 dec. 2023

What?
The procedural content generation framework (PCG for short) is a plugin for Unreal Engine that can be used to procedurally place content in your level such as actors and static meshes. The PCG-graph is the part of the framework where you define the rules and parameters for the generation using nodes. Simplified it could be described as defining what you want to place and where in your level you want to place it.
Why?
The pros of using pcg compared to manual placement is that PCG is easily iterable, reusable and non-destructive, which saves both time and provides flexibility when used to place large quantities of content.
How?
To get started you firstly need to enable the PCG plugins in Unreal. The minimum you need is the plugin called Procedural Content Generation Framework, but I recommend installing the Procedural Content Generation Framework External Data Interop and Procedural Content Generation Framework Geometry Script Interop as well to get the maximum functionality of the framework.
Use Cases
PCG is very useful when it comes to creating scenes with a certain level of randomization such as forests or other vegetation. It is also useful when distributing content along a spline, in grids or to distribute smaller meshes on bigger meshes for example moss on rocks. When placing small quantities of actors or meshes, or requiring a lot of control control over the placement, PCG may not be the best tool to use. In those cases manual placement or the foliage tools may be preferred.
Key concepts of PCG
The PCG Graph
Where you define your logic, a node based framework for visual scripting related to pcg content. Like other node based workflows the data flows through the nodes from left to right.
PCG volume
Spatial bounds for your graph inside your level. Instead of a PCG volume you can use an actor as bounds.
PCG component
A component that references a PCG graph. It is automatically created when placing an instance of a PCG graph inside your level (which creates a PCG Volume with a PCG Component referencing the graph). It can also be assigned to a blueprint actor by creating a PCG component inside of the blueprint and selecting which graph to reference in the details panel of the component.
Points and Attributes
Points in PCG refer to data representations of points in 3D-space. Each point inherently contains a set of predefined attributes (data) such as transform and density, and can be given custom attributes if needed. Points can be debugged from the graph which makes them display visually in the level viewport. These points are then use to decide where in your level you want your content to spawn, as well as to transfer other information such as scale and rotation to the meshes and actors you spawn.
Density
Apart from points, density may be the most important concept inside the PCG graph. Density is a point attribute and is just a name for a float value (usually between 0 and 1) represented by a gradient grayscale value where 0 density is black and 1 density is white. These values are then used to filter out points with a density that are of below or above certain float thresholds. There are several ways of manipulating a points density, spanning from comparing a points normal direction to another specified vector (like a dot product) to using different kinds of generated noise to set the density.
Kommentarer