Posts: 12
Threads: 5
Joined: Apr 2016
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?
Posts: 12
Threads: 5
Joined: Apr 2016
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.
Posts: 690
Threads: 71
Joined: Jan 2015
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.
Posts: 12
Threads: 5
Joined: Apr 2016
haha I think its a tough and long fight that all of us have fought with Unity on some level
Do you think I'll run into trouble down the line by calling Refresh() manually down the line?
Posts: 12
Threads: 5
Joined: Apr 2016
calling Refresh() worked fine until I did a build!
yield return new WaitUntil( () => spline.Count > 0 );
is a good choice for this!
Posts: 690
Threads: 71
Joined: Jan 2015
05-09-2016, 02:03 PM
(This post was last modified: 05-09-2016, 02:03 PM by Jake.)
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...
Posts: 2,113
Threads: 92
Joined: Jun 2017
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.