🟡In this tutorial, we'll guide you through the process of building a versatile spline system using Blueprint in Unreal Engine.
🟡You'll learn how to create a blueprint that allows you to easily add and manipulate spline meshes in your scenes.
🟡From understanding the fundamentals of splines to optimizing mesh assets for deformation, this tutorial covers it all.
🟡Whether you're new to Unreal Engine or looking to enhance your environment-building skills, this tutorial will help you master the art of spline systems.
In a new Unreal Project, make two new folders in the Content folder.
Name one Assets and the other one Blueprint.
In the Blueprints folder, right-click and add a new Blueprint, and rename it BP_SplineTool.
Open the Blueprint, in the upper left corner, click the Add button, and add in the Spline.
In the Viewport, we can see how the spline blueprint will behave.
To control the spline, hold down Alt and move the point to extend the spline.
Open the Construction Script to start making the blueprint for the spline.
Add Allow Scaling and a Branch node.
Allow Scaling lets the user decide whether or not they want to disable or enable the option for their static mesh to scale.
The Branch lets the user enable or disable the Allow Scaling function on their spline. If it's true it will allow the function to happen, if it's false it will do the opposite.
On the left side of the Variables, click the add button to add a node.
Rename it to Length and change it from Boolean to Node.
Add a Get Actor Scale 3D and a Multiply Node.
The Length Float we created is the Length of the static mesh that is going to be on the spline.
Get Actor Scale 3D returns the actor's world space scale.
The Multiply Node allows us to set the value of the Length on whichever Axis is connected with the Length Float from the Get Actor Scale 3D.
Add another new Boolean node, and name it bMatchEnd.
Match End is a Boolean we made for our Branch.
It can allow us to cancel the last asset of our spline so it doesn't match the end of the curve or it can scale it up so it fits the spline curve.
This is the basic setup for a spline blueprint.
We have our spline that we added in the beginning.
It is connected to a Get Spline Length Node that returns the total length along the spline.
The For Loop loops the static mesh that appears on the spline.
Right-click on the Index, promote it to a Variable, and rename that new Component to Count.
The Count will tell us how many static meshes are created inside the spline.
DIVIDE INSTEAD OF MULTIPLY.
Add a Add Spline Mesh Component node.
The Add Spline Mesh Component is the Node that lets us add our static mesh in our spline.
Add a Set Forward Axis node.
The Set Forward Axis Node tells the spline where the static mesh is facing.
We are going to Promote a Variable to the In Forward Axis so we can have the freedom to choose which direction we want our spline mesh to go.
We'll create a new Function for our Start and End Point. We are creating a function so our graph doesn't get crowded. We can do these things inside the Spline Construction Graph but this way it prevents from things getting messy.
Inside the new Function, we'll set an input in the purple node.
After that, we'll set the Location and Tangent Distance with our Length Float.
With the help of a Return Node, we can connect this new Function to our main graph.
Now we can connect with the rest.
Duplicate the STart FUnction, Rename it to End Function, use and add and change it to 1, re-connect it with the Length and Multiply, and lastly change the names from Start to End. In the main graph add in the End Point, connect it with the Set Start and End node as well as with the Count.
Save and Compile the blueprint.
Close the Blueprint, and drag and drop it in the scene.
Like before, hold down Alt and move the points to twist the spline.
To make sure that the end from the static mesh isn’t cut mid-way, make sure that the Match End on the Match End node is turned on.
While the blueprint is selected in the world, in the Details panel, add any static mesh from the project to test out how the spline behaves.