Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CurvySpline.Interpolate() returns (0,0,0) on first frame
#1
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?
Reply
#2
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.
Reply
#3
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.
Reply
#4
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?
Reply
#5
calling Refresh() worked fine until I did a build!

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

is a good choice for this!
Reply
#6
This:


Code:
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...
Reply
#7
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Destroying curvyspline instances jmh1804 5 10 09-18-2024, 07:52 AM
Last Post: _Aka_
  CurvySpline Optimize Candy 1 6 08-02-2024, 08:35 AM
Last Post: _Aka_
  I have a question about curvySpline haifeng.huang 12 33 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_

Forum Jump: