Welcome to this Unreal Engine 5.2 tutorial
on using splines and meshes for Procedural Content Generation. In this tutorial, we will use these tools
to create a fence with multiple components, such as rocks, grass, and flowers. We will then modify the fence by removing
parts of it using a mesh actor, creating a navigable passage. First, we will create an actor blueprint for
our fence. Open the Content Browser and navigate to the
folder where you want to store the blueprint. Right-click and select "Blueprint Class" > "Actor"
to create a new blueprint. Name the blueprint "BP Fence PCG" and double-click
on it to open it in the Blueprint Editor. Next, we will add the necessary components
by clicking the "Add Component" button and selecting "PCG" for mesh generation, "Spline"
for defining the fence shape with a spline, and "Cube" for removing parts of the fence
to create a passage. Then, let's give our spline a tag name "CreateSpline"
so that we can easily identify it later. Click on the spline component to select it,
and in the Details panel, scroll down to the "Tags" section. Click on the "+" button to add a new tag and
enter "CreateSpline" as the tag name. Next, we need to adjust the shape of the spline
to match our desired fence shape. To do this, click on the spline component
to select it, and then select one of the spline points. Move the point to adjust the shape of the
spline. In this case, we want to make the spline longer
by changing the location of one of the points. Then, Click on the box component to select
it, and in the Details panel, scroll down to the "Tags" section. Click on the "+" button to add a new tag and
enter "RemoveActor" as the tag name. Then, scroll down to the "Collision" section
and set the "Collision Enabled" property to "No Collision". Next, scroll down to the "Rendering" section. And check the "Hidden in Game" checkbox to
make the box component hidden during gameplay. To generate the fence procedurally, we will
use a PCG graph. Let's create a new PCG graph and assign it
to the PCG component we added earlier. Right-click in the Content Browser and select
"PCG" then "PCG Graph". Name the graph "Fence PCG". With the blueprint open, in the Blueprint
Editor, select the PCG component in the Components panel. In the Details panel, find the "Instance"
section and expand it. Under the "Graph" dropdown, select the "Spline
PCG" graph that we just created. With our fence blueprint ready, we can now
drag it from the Content Browser into the world to see the changes. Once we've placed the blueprint, we can open
the PCG graph and start editing it to generate the fence mesh procedurally. The first nodes we will add to the PCG graph
are "Get Actor Data" and "Filter By Tag". for the tag filter, we will copy the tag we
added to the cube earlier "Remove Actor" and paste it into the filter. We will also add a comment to this section
of the graph and call it "Actor Data to Remove PCG". Next, we will add "Get Spline Data" and "Filter
By Tag" nodes to the PCG graph. In the tag filter of the "Filter By Tag" node,
we will copy the tag we added to the spline earlier "Create Spline" and paste it into
the filter. We will also add a comment to this section
of the graph and call it "Spline Data to Create PCG". To generate the mesh for our fence, we will
use the "Spline Sampler" node. To the right settings for the node, we will
first create a "Static Mesh Spawner" node and add an array to "Mesh Entries". We will then choose the static mesh that we
want to use for our fence and check its dimensions. To check the dimensions, we can locate the
mesh in the Content Browser and hover over it. In our case, the length of the fence is 330
cm. Next, in the "Spline Sampler" node set the
"Mode" setting to "Distance". then we can fill in the "Distance Increment"
setting with the length of our fence. This will ensure that the mesh is generated
one after the other according to the size of the fence. Next, we add a "Difference" node and connect
the source to the "Spline Sampler" node and the difference to the reroute of the remove
actor data, and the output to "Static Mesh Spawner" node. This allows us to remove the part of the fence
where the cube with the "RemoveActor" tag is located. When we check the spline in the world, we
can see that the fence is generated, but with a part missing at the beginning because of
the actor that removes the data of the PCG. Now, let's rename the cube we added earlier
to "Remove". Then you can modify the cube's scale and location
to create the desired size and position for the hole in the fence. If you want to create more holes in the fence,
simply duplicate the "Remove" cube by holding down the "Alt" key and dragging it to a new
location. You can then adjust the size and position
of the new cube to create another hole in the fence. Now we have a problem when moving the spline,
as we'll see that the generated fence mesh is floating in the air. To fix this, we can project the generated
mesh onto the landscape. In the PCG graph, we can add a "Projection"
node and connect the input to the "Difference" node and the output to the "Static Mesh Spawner"
node. To set up the projection, select our input
for the PCG graph, expand it and drag the landscape onto the "Projection Target" parameter. This will ensure that the generated fence
mesh is properly placed on the landscape. To change the scale of the fence, we will
add a "Transform Points" node to the PCG graph. We'll set the "Absolute Scale" to true and
set the minimum and maximum scales to 2. However, we'll notice that the fence is overlapping
each other. To fix this, we'll need to double the "Distance
Increment" in the "Spline Sampler" node to our new fence size. In our case, that will be 660 cm. Next, let's create some rocks under the fence. To do this, we'll first add the "Create Grid"
node and "Bound Modifier" node to our PCG graph. We'll set the bound min and max to 10 to define
the size of our grid. Then we'll add the "Copy Points" node and
connect the target to the "Spline Sampler" node To ensure that only the closest points are
selected, we'll add the "Distance" node and "Density Filter" node, and adjust the settings
to our liking. We can also add the "Transform Points" node
and change the "Offset" setting to make the rocks appear a bit more random and not in
two straight lines. In the "Distance" node, we will connect the
target to the "Spline Sampler" node. Then, we can copy and paste the "Difference"
node, connect the source to the "Density Filter" node, the difference to our "Remove Actor"
reroute. Next, we will copy and paste the "Static Mesh
Spawner" node and change the mesh to a rock. We will also copy the "Transform Points" node
from the fence and adjust the values to fit the rock's scale. Then, we can copy and paste the "Projection"
node and connect all the pins. We can also add more meshes to the array to
make the rocks more random. Finally, we will select the "Static Mesh Spawner"
node and search for "Collision". We will change the "Collision Preset" setting
to "No Collision" for all the meshes. Great, so now we have our base layer for the
rocks and we can easily create more layers like grass and flowers by simply copying and
pasting all the nodes from the first "Transform Points" to the last node "Static Mesh Spawner"
and changing the settings and meshes as desired. I'll go ahead and create these additional
layers, and you can follow along in the video to see how I do it. With all the layers set up, we can now adjust
the spline and the remove actor to create our final Procedural Generated Fence. And the best part is that we can easily add
or remove holes in the fence just by adjusting the remove actor location or duplicating it. Overall, the PCG approach in unreal engine
allows for a lot of flexibility and creativity in designing our landscape. And that's it for today's video! We have successfully created a Procedural
Generated Fence with multiple layers using Unreal Engine 5.2. I hope this video has been helpful to you
in learning how to create your own Procedural Generated content. Remember, with some creativity, the possibilities
are endless! Don't forget to subscribe for more content
on game development, And Thank you for watching.