Issues Trying to build up a Spline from code

Hi guys, I was trying to build an organic endless road by creating and filling splines directly through code. The idea is to use the spline as a “tileset” to construct the entire path.
Coding it was pretty easy, but I’m facing some issues that I haven’t been able to solve, and I think I may have even found some bug related to working in this way with splines in the construction script.

I’ll share my code so everything will be clearer:

I have an array of “Points” where I randomly reset the YZ location of all the points, except for the first and last ones. After that, I build the spline by adding the points directly from the array and gather all the necessary information from the spline and the static mesh I want to use (in this case, I was trying to prototype using the one called “SM_Track” contained inside the template):

Then I add the meshes. I created a method to build them and achieve the necessary locations and tangents for the consecutive points:



I did the same process for the borders (using one of the walls from the starter content as the mesh):

Everything works perfectly except for the last point of the spline:

All the spline is procedurally generated, but the meshes at the end of the spline have an issue:

The issue with the meshes at the end of the spline

As shown in the last image, at the end of the spline, there’s some excess, as if there’s another point beside the last one (but it doesn’t actually exist).

Another strange thing is that the indices of the points in the spline created from the array need to start from 1, not from 0. If I start the spline by specifying the first point in the array as index 0, I get this issue:

With Index point 0 At the beginning of the spline, it behaves like this:

It’s also impossible to operate on the spline component directly because the asset starts acting strangely, with long compile times and sometimes crashing the engine. I also tried building using one of these “corrupted assets,” and it caused the game to run at 100 fps slower for no apparent reason.

If anyone has any suggestions or can help me solve the issue at the end of the spline, I’d really appreciate it. Also, I’m curious if anyone knows why this strange behavior occurs when trying to modify the component manually. Any insights or advice would be highly appreciated!

I found a way to “fake” the solution, even though it doesn’t completely solve the issue:

I tried using different meshes. The problem is still there, but it’s much less noticeable:

Another thing that helped was skipping the point indices to odd numbers:

This way, the spline looks smoother (it behaves as if there are more points).

The final result (I’m building the path using another BP that acts as a builder; I still need to fix the connection between the two splines, but this gives the general idea):

I forgot to mention that I’m working with Unreal Engine version 5.5.1. Has anyone else run into the same issues and found a proper solution? Also, aside from using the new PCG system, are there any alternative methods or workflows that could achieve a similar result to what I’ve done?

Thanks in advance.