Download

Discontinuous Splines

Hello All,

I am currently having a problem with discontinuous splines. I have created a USplineComponent and have added some points to it. For some of these points I wish to have different arrive and leave tangents. I have set Spline->bAllowDiscontinuousSpline to true and have have set different tangents for the specific spline points by using Spline->SetTangentsAtSplinePoint(…). However when I then play I get a smooth spline everywhere, even though I specifically set some points to have different arrive and leave tangents and therefore be discontinuous.

Any Idea what I might be missing to get discontinuous splines to work?

For reference here are the code snippets I use to add splines and set their tangents:



void UMSplineCreator::AddSplinePoint(USplineComponent* Spline, FVector WorldPosition)
{
    uint8 SplinePointIndex = Spline->GetNumberOfSplinePoints();

    Spline->AddSplinePoint(WorldPosition, ESplineCoordinateSpace::World);
    Spline->SetSplinePointType(SplinePointIndex, ESplinePointType::CurveCustomTangent);
}




void UMSplineCreator::SetTangentsAtPoint(USplineComponent* Spline, uint8 SplinePoint, FVector TangentIn, FVector TangentOut)
{
   Spline->SetTangentsAtSplinePoint(SplinePoint, TangentIn, TangentOut, ESplineCoordinateSpace::World);
}


Thanks in advance,
Bugmee

Did you tried SetSplinePointType method of SplineComponent? Maybe setting type to linear or constant will work for you?

Yes, doesn’t work. And theoretically if it set to CurveCustomTangent I should be able to specify the tangents however I want, right?

I actually need that too. Btw, I checked SplineComponentVisualizer.cpp and it does that:

SplineComp->bAllowDiscontinuousSpline

and then it sets tangents separately:


                FInterpCurvePoint<FVector>& EditedPoint = SplinePosition.Points[SelectedTangentHandle];
                if (SplineComp->bAllowDiscontinuousSpline)
                {
                    if (SelectedTangentHandleType == ESelectedTangentHandle::Leave)
                    {
                        EditedPoint.LeaveTangent += SplineComp->GetComponentTransform().InverseTransformVector(DeltaTranslate);
                    }
                    else
                    {
                        EditedPoint.ArriveTangent += SplineComp->GetComponentTransform().InverseTransformVector(-DeltaTranslate);
                    }
                }

I checked what SetTangentsAtSplinePoint(…) does, and it does basically the same thing. But this made me realize where the error was. It seems that the spline itself is correct. It was just the spline mesh that I then spawn to visualize the spline had some faulty logic. I used GetLocationAndTangentAtSplinePoint to set the mesh’s tangents instead of using the leave tangent of the start and the start tangent of the end.

Thank you very much for your help @scha

For anyone Googling this:

In addition to what Bugmee said, I have found another solution.

I have added following code at the end of my script where I generate points and set meshes:



for (int i = 0; i < NumberPoints; i++)
{
SplineComponent->SetSplinePointType(i, ESplinePointType::CurveCustomTangent, true);
}


NumberPoints is number of spline points available on my SplineComponent.