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
  Rasterized Path Range issue proton 2 12 04-15-2024, 03:42 PM
Last Post: _Aka_
  Curvy discards Input Spline Range VoltDriver 3 5 11-28-2023, 07:14 PM
Last Post: _Aka_
  Error when trying to connect nodes in prefab edit mode Lupos 4 9 06-02-2023, 10:27 AM
Last Post: _Aka_
Bug Argument Null exception Beqo77 5 17 04-24-2023, 08:26 PM
Last Post: _Aka_

Forum Jump: