Spline: Different Length of Tangents

Is it possible to have a different length of tangents. At the moment they are all equal and I can’t find a way to change it.
C++/BP/Editor.

Thanks to ChatGPT:

Yes, it is possible to have different lengths for spline point tangents in Unreal Engine 5’s USplineComponent. Each spline point in a USplineComponent has two tangents: the ArriveTangent and the LeaveTangent. You can set these tangents to different lengths for each point to control the shape of the spline more precisely.

Here’s how you can achieve this:

Accessing and Modifying Spline Point Tangents

To set different lengths for the tangents of each spline point, you need to use the SetTangentsAtSplinePoint function. This function allows you to set the tangent for a specific spline point in the local space of the spline component.

Example Code

Here’s an example demonstrating how to set different lengths for the tangents of spline points:

#include "CoreMinimal.h"
#include "Components/SplineComponent.h"

// Function to set tangents of a spline point
void SetSplinePointTangents(USplineComponent* SplineComponent, int32 PointIndex, const FVector& ArriveTangent, const FVector& LeaveTangent)
{
    if (!SplineComponent || PointIndex < 0 || PointIndex >= SplineComponent->GetNumberOfSplinePoints())
    {
        return;
    }

    // Set the spline point type to CurveCustomTangent to ensure it uses custom tangents
    SplineComponent->SetSplinePointType(PointIndex, ESplinePointType::CurveCustomTangent, false);

    // Set the tangents
    SplineComponent->SetTangentsAtSplinePoint(PointIndex, ArriveTangent, LeaveTangent, ESplineCoordinateSpace::World, true);
    
    // Update the spline to apply changes
    SplineComponent->UpdateSpline();
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.