11-08-2019, 05:03 PM
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
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.