Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Refresh spline doesn't seem to be working
#1
hi, So I'm creating a spline and adding 2 control points, when I try to get a refernce to one of them I get a null ref exception, see code below :
The following code is run ONLY ONCE while the  left mouse button is down :
Code:
drawmousePOS_OBJ = GameObject.Find ("mousePOS");

drawmousePOS_OBJ.AddComponent<CurvySpline> ().Interpolation = CurvyInterpolation.Bezier;
drawing_spline = drawmousePOS_OBJ.GetComponent<CurvySpline> ();
drawing_spline.Add ().transform.position = v3;
drawing_spline.Add ().transform.position = v3;


drawing_spline.SetDirtyAll ();
drawing_spline.Refresh ();

drawtaxiCP0002 = GameObject.Find ("mousePOS/CP0001");
Debug.Log (drawtaxiCP0002.transform.position ); // this line creates a null ref exception
 

the spline & 2 control points are definately there.

But if i change the code so that 
Code:
drawtaxiCP0002 = GameObject.Find ("mousePOS/CP0001");

Debug.Log (drawtaxiCP0002.transform.position ); // works as expected !!

is ran  after the first time the mouse button is down it works.

It even though I'm refreshing the spline it seems like it wont refresh until update is run again.
Reply
#2
Hi,

As a general rule, the GameObject.Find method is an expensive one that should be avoided. In your case, you can avoid using it by doing this:

drawtaxiCP0002 = drawing_spline.Add ();
drawtaxiCP0002 .transform.position = v3;

instead of this:

drawing_spline.Add ().transform.position = v3;
drawtaxiCP0002 = GameObject.Find ("mousePOS/CP0001");

The reason why you had the null reference in the first place is probably because the newly created control point does not get renamed to CP0001 until the next editor update. We can go further in the path of the reasons and solutions regarding that point, but I think there is no need since there is the solution I gave above that avoid calling the Find method altogether.

If my solution does not work please let me know

Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
Thanks ill try that.
Reply
#4
Hi again, I now need to perform operations on a newly created control point, as discussed above it's null to start with, is there a easy way to force it to update as soon as it's created.
Thanks.
Reply
#5
(11-13-2019, 11:50 AM)dazz777 Wrote: as discussed above it's null to start with

It is null even after using the code I suggested?
drawtaxiCP0002 = drawing_spline.Add ();
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Spawn object on Curvy Spline. ktpttd 3 105 11-20-2019, 01:38 PM
Last Post: _Aka_
  Dummy spline points hnngaf 1 66 11-17-2019, 06:01 PM
Last Post: _Aka_
  Same Spline Extrusion with variable width MarioBag 5 818 11-04-2019, 01:56 PM
Last Post: _Aka_
  Change curvy gizmos to show direction of spline Horibe 1 90 11-01-2019, 07:02 PM
Last Post: _Aka_

Forum Jump: