The new Unreal Engine 5.2 Procedural Content Generation Framework is here and it is awesome.
These new tools will allow you to create procedural content in a Houdini-like node scripting toolset so let's dive into it!
As with every plugin, the first step is to activate it. So go to Edit > Plugins and search for the Procedural Content Generation Framework to activate it.
Once you restart the editor you will be able to start working.
The first thing we need to do is to drag a PCGVolume into our scene.
PCGVolumes are one of the main entry points into being able to generate procedural content, think of it as the area in which the generation will take place. For this example we will also want to have a landscape in our scene to generate from, but this can be used with any surface, not only landscapes.
Now that we have defined the area that we want our generation to take place in, what we need is to link that area to a Procedural Graph.
So what we will do is right-click on the content browser and create a new asset, in this case of type PCG Graph:
And we will connect this asset to our PCGVolume to its PCGComponent like this:
Now we are ready to finally generate procedural content. If you open the graph you will see that right now is empty, but with some little work we will soon be able to generate cool things.
The first node we are going to use is a Surface Sampler, to create points on top of the surface and connect the Landscape Height to the Surface input.
The Surface Sampler has multiple options like Points Per Squared Meter or Looseness, but it can be a little difficult to modify those values without visual feedbak.
One helpful thing we can do is to activate the debug functionality of the nodes to see what exactly is going on, this can be done by right clicking and checking the Debug checkbox. ( You can also use the D keyboard shortcut with the node selected )
After doing this, if you go to your viewport you should see a debug representation of the sampled points in the form of boxes with different shades of gray.
Now we have some points, but we want some more variety, so we are going to use the Transform Points node to add variety.
In it's properties we are going to modify both the scale and rotation to add randomness.
This should be now our current result if we enable debug for the Transform Points node:
Now, only one thing remains, to spawn whatever object we want in these points. In this case, we are going to spawn trees to create a little forest by using the Static Mesh Spawner node.
In the properties of this node, we can add entries to the Mesh Entries array to select which meshes we want to spawn and with which weight ( more weight means that the mesh will be more frequent if we have multiple meshes to select from )
So after finally setting up the Static Mesh Spawner node we will finally have a little forest in front of us:
We can do one last thing if we want, we can go to the surface sampler and check the Unbounded checkbox. This will make the PCGComponent use the full landscape.
IMPORTANT! If you do this make sure you properly setup the cull distances of your meshes so they can be culled by distance or your performance is gonna suffer or make your level completely unplayable.
And finally, here we have the result of a huge forest generated with the help of only 3 Procedural Content Generation nodes.
As you can see, this is only scratching the surface of what can be accomplished.
There is so much more to learn and I encourage you to experiment by yourself.
And if you are having any trouble don't hesitate to ping me on twitter and I can try to help you.