#Get selected knot in a spline

1 messages · Page 1 of 1 (latest)

marsh hearth
#

how could I get the selected knot? (See image)
My goal is to be able to move it to the sceneview's camera's position and rotation.

public void MoveSelectedKnotToCamera()
    {
        var sceneView = SceneView.lastActiveSceneView;
        if (!sceneView) return;

        if (Selection.activeObject is CinemachineSplineDolly spline)
        {
            var splineContainer = spline.Spline;
            if (splineContainer.Splines.Count == 0)
            {
                Debug.LogError("No splines found on selected asset!");
                return;
            }
            var existingSpline = splineContainer.Splines.First();

            // todo: now I need to get selected knot in spline, but I can't find any matching funciton!           
        }
    }

In the following image, the first knot is selected.

tender fox
marsh hearth
# tender fox Selection is not something that is stored in the spline component. It’s an inspe...

thanks a lot Anikki, I got it working eventually but I'm sure there's a better way to achieve it,
ChatGPT mentions functions like:

var selection = EditorSplineUtility.GetSelection();
var spline = selection.Spline;
int knotIndex = selection.KnotIndex;

which all of those seems to be removed in the new splines version from 2022

I'm just really confused why I would need a list of SplineInfo of containers if I only have a single SplineContainer component per object,
this List will never have more than one item