Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Argument out of range (index) error on DistanceToTF
#1
Hi all, I've got a pretty simple setup: a single spline linked to a script, where at Start() I need to analyze the curvature of the spline, so I do:


Code:
float tf = 0f;
float distance = 0.0f;
while(tf < 1){
    tf = spline.DistanceToTF(distance);
    ...
}

Even though the Spline is correctly linked and instantiated, I get:

Code:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
At line 519 of CurvySpline.cs, where DistanceToSegment gets mSegment[0].  An mSegment.Count before that line returns 0.  Not sure what to try next.
 

There definitely seems to be a delay before you can access the spline for some reason.  If I stick

Code:
Debug.Log(spline.TFToSegment(0f));
into an Update(), the first one gives a NullReferenceException but all subsequent ones work.  How should we work around this?
 

Ah. Just discovered  CurvySpline.IsInitialized.  My bad.
Reply
#2
Yeah, Unity initialization order isn't predictable (unless you specify script priority in the settings), so you always have to wait until Spline.IsInitialized==true
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Error after upgrade: (are you missing a using directive or an assembly reference?) boriskourt 3 5 05-17-2022, 12:32 PM
Last Post: _Aka_
Exclamation Runtime error when using Curvy Generator with Game Object Deform studentloan 3 10 04-22-2022, 09:00 PM
Last Post: _Aka_
Question Spline path "Range" option: how to go from end to start CP? niuage 4 10 03-07-2022, 10:48 AM
Last Post: niuage
  Problem with combining shape extrusion and DistanceToTF kazlik 3 3 01-08-2022, 11:53 AM
Last Post: _Aka_

Forum Jump: