Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Duplicate CurvySpline
#1
Hello, I would like to know if it's possible to duplicate a CurvySpline by code please ?
Thank you
Reply
#2
Hi,
A simple
Code:
Instantiate(yourSpline);
will do it.
In case you are not familiar with this method, it's a Unity method that duplicates a gameobject.

If you want to have more control on the copying process, you can make some custom copying code that will look like this:
Code:
   void Clone(CurvySpline spline)
   {
       var clone = CurvySpline.Create(spline);
       foreach (var controlPoint in spline.ControlPointsList)
       {
           CurvySplineSegment newControlPoint = clone.Add(controlPoint.transform.localPosition)[0];
           CopyDataFrom(controlPoint, newControlPoint);
       }
       clone.Refresh();
   }

   //warning: this does not handle metadata and connections
   static void CopyDataFrom(CurvySplineSegment source, CurvySplineSegment destination)
   {
       destination.transform.position = source.transform.position;
       destination.transform.rotation = source.transform.rotation;
       destination.AutoBakeOrientation = source.AutoBakeOrientation;
       destination.SerializedOrientationAnchor = source.SerializedOrientationAnchor;
       destination.Swirl = source.Swirl;
       destination.SwirlTurns = source.SwirlTurns;
       destination.AutoHandles = source.AutoHandles;
       destination.AutoHandleDistance = source.AutoHandleDistance;
       destination.HandleOut = source.HandleOut;
       destination.HandleIn = source.HandleIn;
       destination.OverrideGlobalTension = source.OverrideGlobalTension;
       destination.OverrideGlobalContinuity = source.OverrideGlobalContinuity;
       destination.OverrideGlobalBias = source.OverrideGlobalBias;
       destination.SynchronizeTCB = source.SynchronizeTCB;
       destination.StartTension = source.StartTension;
       destination.EndTension = source.EndTension;
       destination.StartContinuity = source.StartContinuity;
       destination.EndContinuity = source.EndContinuity;
       destination.StartBias = source.StartBias;
       destination.EndBias = source.EndBias;
   }
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Duplicate Volume references become null joebain 5 33 11-18-2024, 10:46 AM
Last Post: joebain
  Destroying curvyspline instances jmh1804 5 10 09-18-2024, 07:52 AM
Last Post: _Aka_
  CurvySpline Optimize Candy 1 6 08-02-2024, 08:35 AM
Last Post: _Aka_
  I have a question about curvySpline haifeng.huang 12 33 07-14-2023, 09:34 AM
Last Post: _Aka_

Forum Jump: