Procedural Content Generation in UE5 with PCG
Create vast, varied environments without placing every asset manually. PCG lets you define rules, and Unreal generates the content.
What is PCG?
The Procedural Content Generation (PCG) framework is Unreal Engine 5's system for creating content through rules rather than manual placement. Instead of placing thousands of trees individually, you define where trees should grow, how they should be distributed, and what variations exist. PCG handles the rest.
PCG graphs are node-based visual scripts that process point data, filter it based on conditions, and spawn actors or instances at the resulting locations. Think of it as a pipeline that transforms abstract rules into concrete level content.
PCG Framework Basics
Understanding PCG's core concepts is essential before building graphs.
PCG Components
The PCG Component is an actor component that runs PCG graphs. Add it to any actor to make that actor a PCG generator. The component defines the execution bounds, input pins, and generated content management.
// Adding PCG Component in C++
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UPCGComponent* PCGComponent;
// In constructor
PCGComponent = CreateDefaultSubobject<UPCGComponent>(TEXT("PCGComponent"));PCG Graphs
PCG Graphs are assets that define the generation logic. They contain nodes that sample surfaces, generate points, filter data, and spawn results. Graphs are executed by PCG Components.
// Creating a PCG Graph
1. Content Browser -> Right Click -> PCG -> PCG Graph
2. Double-click to open the graph editor
3. Add nodes to define generation logicData Types
PCG operates on several data types that flow through the graph:
- Points - Spatial positions with attributes (transform, density, etc.)
- Spatial - Surfaces, volumes, and splines
- Param - Named parameters for configuration
- Attribute Set - Collections of named values
Creating PCG Graphs
Let's walk through creating common PCG setups from scratch.
Basic Point Scattering
The simplest PCG graph scatters points across a surface and spawns meshes at those locations.
// Simple scatter graph structure
1. Get Landscape Data -> Samples points on landscape
2. Surface Sampler -> Generates points on the surface
3. Density Filter -> Removes points randomly based on density
4. Static Mesh Spawner -> Creates mesh instances at remaining pointsConfigure the Surface Sampler's points per square meter to control density. The Density Filter uses each point's density attribute to probabilistically keep or remove points.
Forest Generation
A realistic forest requires more than random scattering. Trees should cluster, vary in size, and respect terrain features.
// Forest generation graph
Get Landscape Data
|
Surface Sampler (PointsPerSquareMeter: 0.1)
|
Slope Filter (Keep: 0-30 degrees) // Trees don't grow on cliffs
|
Density Noise (Perlin noise for clustering)
|
Density Filter (Threshold: 0.4)
|
Branch: Large Trees (10%), Medium Trees (30%), Small Trees (60%)
|
Static Mesh Spawner (per branch, different meshes)
|
Transform Points (random rotation, scale variation)Road-Aware Placement
Content shouldn't spawn on roads or in buildings. Use exclusion zones to define where content cannot appear.
// Using splines for exclusion
Get Spline Data (Road spline)
|
Spline Sampler
|
Create exclusion volume (width of road + margin)
|
Difference with scatter points
|
Remaining points spawn contentBuilding Interiors
PCG can populate building interiors with furniture, decorations, and clutter based on room boundaries.
// Interior decoration graph
Get Volume Data (room bounds)
|
Volume Sampler
|
Edge Detection (find walls)
|
Branch: Wall placement, Floor placement, Corner placement
|
Asset selection based on position
|
Static Mesh Spawner with collision avoidanceAdvanced PCG Techniques
Once you understand basics, these techniques enable more sophisticated generation.
Attribute-Based Selection
Points carry attributes beyond position. Use these to drive asset selection and configuration.
// Attribute-driven spawning
Get Landscape Data
|
Sample landscape material (writes MaterialIndex attribute)
|
Branch on MaterialIndex:
- Grass material -> Grass/flower assets
- Dirt material -> Rocks/debris assets
- Sand material -> Desert plants assetsHierarchical Generation
Large environments benefit from hierarchical generation where primary elements influence secondary elements.
// Village generation hierarchy
Place Village Centers (sparse, rule-based)
|
For each village:
|
Generate Building Footprints (around center)
|
For each building:
|
Populate interior
|
Generate surrounding yard
|
Place yard decorationsBiome Blending
Transitions between biomes should blend naturally. Use gradient values to mix content from different biomes.
// Biome blending
Get Biome Map Texture
|
Sample at each point (gets biome blend values)
|
For each biome:
|
Density = original * biomeWeight
|
Spawn biome-specific assets
|
// Result: smooth transitions with mixed vegetationRuntime Generation
PCG can generate content at runtime for infinite worlds or procedural dungeons. Use Generate on Load and Stream with PCG Volume bounds.
// Runtime PCG settings
PCG Component:
- Generation Trigger: Generate on Load
- Is Partitioned: true (for streaming)
- Use 32-bit seed for deterministic generation
// In C++
PCGComponent->Generate(true); // Force regenerationPerformance Optimization
PCG can create thousands of instances. Optimization is essential.
Hierarchical Instancing
Use Hierarchical Instanced Static Meshes (HISM) for PCG spawning. This drastically reduces draw calls for repeated meshes.
// Instancing settings in Static Mesh Spawner
Mesh Spawner Mode: Instanced Static Mesh
Enable Hierarchical Instancing: true
// Culling settings
Instance Start Cull Distance: 5000
Instance End Cull Distance: 10000LOD Integration
Ensure spawned meshes have proper LODs. PCG can also select different assets based on distance for additional optimization.
Generation Partitioning
For large worlds, partition PCG generation to match World Partition cells. Only generate content for loaded cells.
// Partitioned generation
1. Enable Is Partitioned on PCG Component
2. Set Partition Grid Size to match World Partition cell size
3. Content generates per-cell on demandCaching Results
For content that doesn't change, cache PCG results to avoid regeneration on every load.
// Caching options
PCG Component:
- Generation Trigger: Generate on Demand
- Cache Generated Data: true
// Or bake to static actors
PCG Graph -> Execute Graph -> Convert to Static ActorsDebugging PCG
When PCG doesn't produce expected results, use these debugging approaches.
Debug Visualization
// Enable debug display
PCG Component -> Show Graph Debug: true
PCG Component -> Debug Display Mode: Points
// See intermediate results
Add Debug node after any node to visualize that stageAttribute Inspection
// View point attributes
Add Print Debug node to output attribute values
Check PCG Output Log for detailed execution infoCommon Issues
- No output: Check that input data covers the generation bounds
- Wrong placement: Verify coordinate spaces match
- Missing collisions: Enable collision on spawned instances
- Performance spikes: Profile graph execution, optimize filters
Integration with UnrealPilot
Creating and iterating on PCG graphs involves significant trial and error. UnrealPilot accelerates the process dramatically.
Creating Graphs
"Create a PCG graph that scatters rocks on slopes steeper than 30 degrees"
"Generate a forest with clustering using Perlin noise, exclude areas
within 500 units of any road spline"
"Create a PCG setup for procedural city blocks with buildings, roads,
and street decorations"UnrealPilot generates complete PCG graphs with proper node connections, configured parameters, and appropriate asset references.
Modifying Graphs
"Add a height-based filter to my forest graph - no trees above 2000 units"
"Make the rock scatter denser on south-facing slopes"
"Add LOD switching to spawn simpler meshes beyond 3000 units"UnrealPilot understands existing PCG graphs and can add nodes, modify parameters, or restructure logic based on your requirements.
Debugging Help
"My PCG graph isn't spawning anything - help me debug"
"The density is too high in some areas and zero in others - how do I
smooth it out?"
"Content is spawning inside buildings - how do I exclude interior volumes?"UnrealPilot analyzes your graph, identifies likely issues, and suggests specific fixes.
Converting Manual Work
"I manually placed 500 trees - convert this to a PCG graph that matches
the distribution"
"Analyze my hand-placed rocks and create a PCG graph that produces
similar results"UnrealPilot can analyze existing content placement and generate PCG graphs that reproduce similar distributions, freeing you from tedious manual work.
PCG in Production
Real-world PCG usage requires thinking about iteration, collaboration, and content management.
Version Control
PCG graphs are assets that can conflict in version control. Use clear naming, document graph purposes, and consider modular graph design where subgraphs handle specific tasks.
Artist Override
Allow artists to override PCG results where needed. Mark specific actors as persistent to prevent PCG from removing manual placements.
// Protecting manual placements
1. Set actor's PCG Exclude tag
2. PCG will not modify or remove this actor
3. Artists can hand-place key elements while PCG handles the restDeterministic Seeds
For consistent results across team members and builds, use fixed seeds rather than random seeds.
// Seed management
PCG Component -> Use 32 Bit Seed: true
PCG Component -> Seed: 12345
// Or use position-based seeding for tile-independent consistencyStart Generating Content
PCG transforms how you build environments. Instead of placing thousands of assets manually, you define rules and iterate on them. The initial investment in learning PCG pays off enormously for any project with significant outdoor environments.
Combined with UnrealPilot, PCG becomes even more accessible. Describe what you want, and AI generates the graph. Iterate through natural language rather than node manipulation. Build vast worlds faster than ever.