Unity Splines

Hi Thomas,
I want to add a knot through code.
Could you please let me know the solution?

1 Like

I would first evaluate the position and tangents at the position where you want to insert your new knot, using Spline.Evaluate().
Then using the Spline.Insert() method, I would add this BezierKnot, is the tangent correctly set, at the relevant index on the spline.
Don’t forget to change the tangent mode to Mirrored and that should do the trick :slight_smile:

Hmm, I still can’t get it to work.
This is my code (one example):

public class SplineTest : MonoBehaviour
{

    public SplineContainer splineContainer;
    public float t = 0.5f;


    private void Start()
    {
        var spline = splineContainer.Spline;
        
        spline.SetTangentMode(TangentMode.Mirrored);
        
        spline.Evaluate(t, out var position, out var tangent, out var upVector);
        
        var knot = new BezierKnot(position, tangent, tangent, quaternion.identity);
        
        spline.Insert(1, knot, TangentMode.Mirrored);
    }
}

This is the original spline:

and after Start:

So the problem is that evaluating the tangents returns a tangent length which I can’t use and setting the tangent modes to Mirror doesn’t help (if I’m doing this correctly?).

Yes I can make that soon.
Do you prefer two different bug report, or one bug report for the two?

Ah, and for bug reporting, it could be tons better for us to have a direct support/bug-report link (to the concerned team) from the package documentation page.
(There is just no contact/support form of any kind on each package documentation, really…)

And a quicker way to communicate and track your fixes could be easier for you and us to work togheter in order to resolve issues and improve your packages.
:stuck_out_tongue_winking_eye: :slightly_smiling_face:

@ThomasLopez A simple feature that clearly miss, is a invert spline points button. (for reverting the point order when the spline has been created from the end, and don’t having to manually revert that in the point reorderable list…)

Isn’t it the “Reverse Spline Flow” button visible in this post image?

Hi there. I must be dumb. I can’t figure out how to insert knots along a spline edge. In the manual it has a section on the Knot Placement Tool which looks like what I need, but I don’t seem to have such a tool showing nor can I figure out how to enable it. Anybody can help?

I think the buttons are not visible now. Instead, we have to right-click on a knot to see these options.

Thanks for reply. When I right click I don’t see any way to insert a knot, and split is disabled. Really funky. Is there really no way to insert/remove knots easily?

For each knot I need to know the t value. Is the only way to sample the spline myself or using GetNearestPoint and pass the knot position in to get the float t out?

Just select the spline and go to the Draw Spline Tool.
Now you can click anywhere in the spline to add a Knot.
Press ESC to disable the tool.

The split won’t work on the start or end Knot of a spline and
make sure the selected Knot is not linked Knot.

Edit: If you are trying to extend the spline, You can click on the end knot after selecting the Draw Spline Tool and continue drawing the spline.

I’m also using the GetNearestPoint function to get the t Value.
I don’t know any other way.

If you are trying to find alternative methods due to performance issues, You can try out the NativeSpline method for GetNearestPoint inside the burst compiled Job.

Yes, that worked. Thanks! I thought I tried it before but the spline tool seems a little funky sometimes. Appreciate the help.