SplineMesh bug when doing looping

I’m trying to create a racing game with a crazy track with loopings, corkscrews and twists. I using spline mesh to deform track sections. What I want to do is a Construction Script that has a Transform variable with a Widget manipulator to set the end point and end rotation.

When I try to do a looping, a bug on the deformation occurs, as shown here:

This seen to be gymbal lock ocurring during the deformation.

If I set the roll to 180 degres to get the ending upside down, the problem get worse:

This the expected behaviour (did it on modeling software):

Is there a way to solve this? Or is it realy a gymbal lock bug due to internal calculations using euler angles instead of quaternions?

Using UE4.4.1 binary version.

Hi Jandex,

In the Details panel > Spline Mesh > Play with the values for “SplineUpDir”. This will usually correct most of these twisting issues.

If it doesn’t, could you post your asset so we can test it further?



Thanks TJ Ballard for the answer.
But I think tweaking UpDir doesn’t solve it. Just moves the problem to another situation. For example, I changed Up to (0 ,1 ,0) , and got this:

I can do loop but can´t do a curve.
If I put (1 ,0 ,0) I can do curve and loop, but can´t do straight line.
I short, the problem always occurs when the spline direction gets aligned with the Up Dir.

Maybe a solution would be having a Start Up Dir and End Up Dir, and interpolate those along the spline. This would replace the roll parameter.
Or there may be a better solution.

Here is the [link][2] for the assets.

Hi Jandex,

So here is the solution I came up with. I made a slight twist using the SplineUpDir and then adjusted the Start & End Roll values. If you set the values as I have pictured below it should work.



1 Like

Thanks for this! I’m currently going through the same issues and this solved them.

Sorry for the delayed response. I was away from the computer these days.
Thanks TJ Ballard for the help, but this doesn’t solve it.

Let me be more clear of what I’m trying to achieve.
I want to create a tool to create a racing track F-Zero style.
My ideia is to have a sequence of deformed spline meshes conected one end to the start of the other. Those spline meshes should be manipulated by gizmos in the editor. I would have a start transform and end transform for each spline mesh, and the spline mesh should interpolate between those transforms.

The problem is, due to the method used to deform the mesh by spline, whenever the spline aligns with the up vector the mesh twists around it self.
Don´t matter what up vector I put, if the track goes in there direction there will be this unwanted twists.

My issue is not with one specific case that will work, but is to have a tool that will behave properly in all cases.

Here is the link to download the Spline Track Blueprint with Widget manipulators for you to test it. Add one instance to the level and try moving and rotating the end Widget.

(obs: I also submited another bug due to Widget gizmo orientation)

Ah okay, I see what you mean now. I don’t believe this is currently possible with SplineMeshes but it could be fixed if the ‘Spline Up Dir’ was exposed like the rest of the values in blueprints. A variable could be created and made public, this would allow each blueprint to be adjusted as needed.

I created a Feature Request in our tracking software for this and our developers will be looking into it further.



Thank you very much! I will stay tuned for it in the next updates

Hi Jandex,

This has now been fixed in our latest internal build. You should see a ‘Get Spline Up Dir’ and a ‘Set Spline Up Dir’ node in a future update.



Geeze… I feel like a total idiot… I’ve been struggling with a similar issue (the infamous gimbal lock) for a long time and assumed that was inherently unavoidable without using quaternion. Had to work around that using convoluted solution… Feels good to know there is an easy fix.

I still see the twist in 4.21.2. Tweaking the “up vector” does not solve the issue, only moves it around.

@roberteker There’s a property called Default Up Vector for the spline mesh in the details panel. Play with the values and it should un-twist itself. Had the same issue and I tweaked the X value to around -200 and the twist solved itself.

That does not work when you have a full loop and other twists on the same spline.

I had to purchase a marketplace asset that was able to have individual up vectors per spline point.

It’s really quite poor of Epic to leave this flaw in for several years.

Hi ,
I have been trying to create a procedural splineMesh using spline component and adding splineMesh to that component depending upon the number of spline points , which of course most of us would do.
while doing so i got this twisting issue ,i tried to look for solution , well none of it worked for me. But i found out it is related to spline Mesh Up vector ,so basically i will need to update spline mesh up vector , but there are so many spline meshs i just need to do it for each one individually.
I found a plugin which was desgined for this kind of problem which will allow you to edit each spline mesh Up vector indivually.
so i thought of implementing it myself and it works like charm .

Maybe it will help you guys too.

I have used an array of vector which is InstanceEditable and desgined to have number of items in array equilaent to number of spline meshes.
Then i have updated each spline mesh’s up vector from that Array , so basically i can control each splineMesh UpVector individually.|

This is how i have done this . sorry for congested Nodes in Bp , this is the only way i could get this in a single ScreenShot.



I solved the twist with an automatic calculation of an Up Direction for each spline mesh.

I calculate the direction as a cross vector of the start and end tangents. It only fails if the tangents are parallel vectors, in which case I made a conditional that shuffles the components of the first tangent, giving me a perpendicular vector to both tangents.

Then I just apply this vector to the Spline Mesh using its Set Up Direction function. That way I don’t have to manually decide the up vectors myself.

The local variables in the screenshot were used to avoid recalculation of the normalizations and dot product.


For me, I discovered the issue was that UE4 expects your mesh to be modeled with the length running down positive X and your Z axis to be your up axis. Although the settings in the Spline Mesh component allow for you to specify another forward axis and up direction, setting these to match my mesh didn’t fix the problem. As soon as I adjusted my mesh to match UE4’s defaults, the pinching disappeared;

Hi! I know it’s been a long time but… can you explain your answer a bit more? I implemented ur function but it is twisting the whole spline hahah

FVector AProceduralTrackGenerator::ComputeSplineMeshUpVector(FVector TangentA, FVector TangentB)
	FVector NormalA = TangentA.GetSafeNormal();
	FVector NormalB = TangentB.GetSafeNormal();

	FVector UpVector;

	float dot = FVector::DotProduct(NormalA, NormalB);

	if (dot > 0.99f || dot <= -0.99f)
		UpVector = FVector(NormalA.Y, NormalA.Z, NormalA.X);
		UpVector = FVector::CrossProduct(NormalA, NormalB);

	return UpVector;

Then i’ve use it this way

		// Set up direction
		FVector UpVector = ComputeSplineMeshUpVector(StartTangent, EndTangent);

And this is the result, the track was aligned horizontally with the floor

This function worked great for me needing to take the twist out of my cylinder spline mesh. Thank you!

1 Like

I’ve used the above code to try to fix the twisting I had (which to be fair was fairly minor) but I am finding that either the start or end points now don’t render. Any ideas to what is going on, worth saying I am also setting the forward axis of my mesh.

1 Like

I also had this issue and thought I would make a quick note here. I set the forward axis of the mesh from Y to X (in Blender). In the blueprint I set the ‘Add spline mesh component’ ‘Forward Axis’ to X. Then deleted the blueprint from the scene and placed in back in again and this did fix the issue for me.