Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CurvySpline cannot find its own segments
#1
Question 
Here's a weird one. I've got a collection of objects, all prefabs, which each contain a CurvySpline object. Each spline already has its Segments placed. My code instantiates an object in the scene, then calls a function to add the CurvySpline from the new object into the main SplineGroup. The spline group addition works perfectly, however I want to make sure the start / end points of the splines match up, so I'm trying to get the segments. Problem is, the spline doesn't seem to know they exist, even though the path itself runs correct when objects are placed on it.

Here's my code with notes on what each debug output does:

Code:
    private void connectBlockSplines(CurvySpline inSpline)
    {
        movementPathSplineGroup.Add(inSpline);

        Debug.Log(inSpline.Segments.Count + " / " + inSpline.ControlPoints.Count); // Always shows 0 / 0
        Debug.Log(inSpline.FirstVisibleControlPoint); // Always shows null
        Debug.Log(inSpline.LastVisibleControlPoint); // Always shows null
    }

Am I doing this wrong? Any tips on how to properly get the spline segments?

Thanks!
Reply
#2
Could you please add a check to see if inSpline is fully initialized?



Code:
Debug.Log(inSpline.IsInitialized);

If not, simply use the default Start()-mechanism to wait for it's initialization (a.k.a. while (!spline.IsInitialized) yield return 0; ). If it's initialized, further investigation is needed.

 
Reply
#3
Jake,

That was exactly the problem, thank you! I've resolved it by adding all the splines into a new Stack object that makes sure they are in order, then on each Update I call the following function:

Code:
    private void connectBlockSplines()
    {
        if(addSplineStack.Count == 0)
            return;

        bool doneAdding = false;
        while(!doneAdding)
        {
            CurvySpline nextSpline = addSplineStack.Peek();
            if(!nextSpline.IsInitialized)
                doneAdding = true;
            else
            {
                movementPathSplineGroup.Add(nextSpline);
                addSplineStack.Pop();

                if(addSplineStack.Count == 0)
                    doneAdding = true;
            }
        }
    }

They get added in order regardless of the order they become initalized in and the debug functions I mentioned before that crapped out now show proper data. 

Thanks again!!
Reply
#4
You're welcome!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find out whether the spline is self-intersected. mydayz 1 54 10-19-2021, 12:08 PM
Last Post: _Aka_
  CurvySpline Editor event ATHellboy 1 1,661 03-08-2020, 01:51 PM
Last Post: _Aka_
  [Fixed]CurvySpline.Length can return 0 during init stage c0ffee 2 2,003 01-16-2020, 01:56 AM
Last Post: c0ffee
  How to find connections dazz777 5 3,560 09-12-2019, 11:08 AM
Last Post: _Aka_

Forum Jump: