Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Argument out of range (index) error on DistanceToTF
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:

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:

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

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.
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  DT Singleton Instance was null error Rick76 3 285 10-07-2021, 05:59 PM
Last Post: _Aka_
  Whitespace error in UITextSplineController kasai@cadcenter 4 642 07-09-2021, 09:07 AM
Last Post: _Aka_
  Error while making prefab having curvy Generator script User2200 3 1,146 03-15-2021, 07:16 PM
Last Post: _Aka_
  Spot generator range change Mos Def 4 1,159 02-24-2021, 07:32 PM
Last Post: Mos Def

Forum Jump: