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
  I have a question about curvySpline haifeng.huang 12 32 07-14-2023, 09:34 AM
Last Post: _Aka_
  CurvyGenerator not refreshing until next frame when created. Lupos 2 7 06-08-2023, 12:12 PM
Last Post: _Aka_
  "Deadloop in CurvySPline.Refresh" spam Valkymaera 3 11 05-30-2023, 10:56 AM
Last Post: _Aka_
  Optimum configuration for frame-by-frame updates FanManPro 5 11 04-10-2023, 10:13 PM
Last Post: _Aka_

Forum Jump: