Create a spline rail supported by pillars reaching the ground

Hi, there! One simple thought - to spawn full StaticMeshActors as the pillars instead of creating a bunch of components. By that you can save normal scale for SplineRail and independently scale pillars. Maybe you can even make use of Hierarchical Instanced Static Meshes to catch some optimization (see Unreal* Engine 4 Optimization Tutorial, Part 2)

Hello guys,

I hope you are doing well,

I have a question regarding something I want to achieve in my project.

I would like to create a Spline Blueprint that will be represented by a rail supported by pillars (kinda like a rollercoaster). I would like the support pillars to be automatically built from the spline down to the ground.

On construction script of the blueprint, I use a spline component which is composed of Spline Meshes. This, I managed to do pretty easily (see screenshot)

Then, I want to add “support pillars” to my spline (kinda like columns that support the Spline rail) every 1000 meters or so.
I managed to do this as well with a constant Z scale for the pillars (they are all the same height)

However, where I’m struggling is that I want the pillars to stretch in Z scale from my spline component down to the ground (in order to save time and not have to place all the support pillars manually).
The problem is that if you stretch in Z, the offset of my pillars also get messy since the scale is not increased in only one direction of Z but both upward and downward.

I’ve been trying to use Line Trace on Objects fired downward on the construction script of my spline blueprint with the start being the Spline point location and the end being the hit detection with World Static mesh (the ground).

But this is not really working and I had no luck finding a way to achieve what I want. Basically, the best case I managed to reached is to have the “pillars” with their normal size and hard code the offset (since the Z scale of my pillars are the same for every of them).

What would be your advice to do such automatically generated pillars that reaches the ground ? What would be the math behind it ?

Thank you in advance for your replies,

Wish you the best,

Sanglard

Hello again,

Shortly after posting this, I manage to found how to do it ! (whereas I was struggling for several hours this afternoon).

I found the hit location at ground and set the location of my pillars to this one. Then, I rescale my pillars using the difference of Z between the spline point and the ground point and I divide the difference by 1000.

I still don’t undestand why dividing by 1000 works though. I found this with trial and error !

Still thank you Kehel for the other idea !

Cheers from France :slight_smile:

Actually I still have a problem. The hard coded 1000 value is not fitting anymore when I move my ground location. I still need the math to find by what number I need to divide my difference between the Spline point Z and the ground Z.
Any advice is welcome :slight_smile:

Dear valued Unreal Engine user,

What you have done so far looks great!

In terms of finding the distance to the ground, a line trace looks the simplest way to go from where you currently are. If you are scaling a static mesh, how it scales would depend on how the mesh itself is centered. For example the default cylinder static mesh’s center of the cylinder is at the origin, so it will scale in both directions about the center by half the amount you scale. So after scaling, would then offset the mesh by half of the new size of the mesh.

To find out how much to scale it by you should be able to get the local bounds of the static mesh, take the max minus the min, and break the vector out to grab just the Z (height). Divine the distance from the hit-test by that height, to get the amount you should scale the mesh’s Z by. Once you have done that, assuming your mesh is centered about the origin, you can offset the mesh by half of the distance from the hit-test.

Instead of stretching, as that would also scale the support planks/beams crossing the pillars, you might be able to construct a blueprint that procedurally generates a pillar from a smaller number of static meshes. For example if you give the blueprint a height as an input, you scale the left and right struts, and then add in additional cross-beams based on the height. That way the cross-beams would remain the same scale, and just increase in number.

Thank you for your continued support,

Hello ,

Thank you for your detailed reply ! :slight_smile:

I actually managed to find the solution 10 minutes after posting this haha ! But I did basically what you said. I used the mesh bounds and it works perfectly !

The only difference is that I used the Line Trace to find the ground location and set the pillars location to this value (meaning they were all shifted to the ground below my spline) and then I made the modification on the Z scale. I’m not using the “Add Local Offset” node anymore.

Thank you again, I’ll hope this post will be useful to someone else :).

Bye !

Sanglard