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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#6
(11-13-2019, 11:13 PM)_Aka_ Wrote:
(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 ();

Hi, Sorry It so long to reply ( got sidetracked with other things ), yes this works I just needed to change drawtaxiCP0002 to a curvysplineSegment 
( it was a Gameobject !!) but as I can get and set the handles in/out position and I assume change the positon of the control point then thats fine.

Thanks.
Reply
#7
You are welcome
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
  Method of scattering objects along spline joebain 1 3 11-26-2024, 03:20 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 5 13 10-29-2024, 10:19 AM
Last Post: _Aka_
  I have to refresh generator manualy :( GameDeveloperek4123 4 13 10-07-2024, 05:36 PM
Last Post: _Aka_
  Nested Spline Volume Spot Instantiation merobbins5 3 7 07-26-2024, 09:58 AM
Last Post: _Aka_

Forum Jump: