Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CurvySpline.Interpolate() returns (0,0,0) on first frame
I'm finding that when I call CurvySpline.Interpolate() from Start(), Awake() or in Update() on the first frame after starting, it always returns (0,0,0).

If I call it from an editor script when not in playback mode or on any subsequent frames after the first, it returns what I expect, but as I'm trying to set positions in Start(), this behavior is frustrating. Any advice?
It seems that the CurvySpline clears mSegments in OnEnable() so the Count property returns 0. I'm not really familiar with the innards of CurvySpline.cs, but it seems like it ought to call its Refresh() method immediately after? Being able to get points on a spline reliably on first frame without messing with Script Execution Order seems reasonable.

For now, I'm manually calling refresh from my class if Count == 0.
It would be reasonable if all data goes to a single GameObject, otherwise you run into problems due unpredictable initialization order. Multiply that with different magic function order in the editor and connected GameObjects... it's not as simple as it looks at first and I fought a tough and long fight with proper initialization.

To sum it up: at runtime you'll need to wait until the spline is initialized, using yield in Start() and/or a simple if-then in Update(), no way around that. That goes for Controllers and Curvy Generators as well.
haha I think its a tough and long fight that all of us have fought with Unity on some level Wink

Do you think I'll run into trouble down the line by calling Refresh() manually down the line?
calling Refresh() worked fine until I did a build!

yield return new WaitUntil( () => spline.Count > 0 );

is a good choice for this!

IEnumerator Start()
  while (!mySpline.isInitialized)
     yield return 0;

Just wait until all Curvy stuff is initialized, then proceed with your other setup code. May be one frame, may be two for some reasons...
Improvement regarding this was done in Curvy 2.2.4. Now splines are initialized in their Start method (old behaviour was initialization at the first update method).
Curvy 2.2.4 should be available very soon (it's right now going through Unity's assets approval process)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.

Possibly Related Threads…
Thread Author Replies Views Last Post
  interpolate to nth control point appropriate_ladder 1 289 02-22-2021, 08:27 AM
Last Post: _Aka_
  CurvySpline Editor event ATHellboy 1 1,355 03-08-2020, 01:51 PM
Last Post: _Aka_
  [Fixed]CurvySpline.Length can return 0 during init stage c0ffee 2 1,711 01-16-2020, 01:56 AM
Last Post: c0ffee
Information [Quick and dirty] Shape Extrusion: interpolate between multiple Crosses _Aka_ 9 8,718 09-02-2019, 09:42 PM
Last Post: _Aka_

Forum Jump: