Dynamically Add Points to Spline

I am trying to create a randomly generated tube. I would like the camera to fly through the tube. To do this I am using the Hermite Spline Controller, the javascript version,and when a tube piece is instantiated I take a child from the front of it, and add it to the Spline Root. The new spline points are added properly, the red line connects them at least, but for some reason the camera won’t follow. If I add a few points before hitting play the camera will go to those but no further. How can I make this work properly.

One theory that I have yet to test is that maybe the problem is that the objects I am adding to the spline are cylinders v
ersus using empty game objects.
The camera has moved to the first point that was created before play, the rest of the line was generated at game time.

It looks like I need someway to update the current Interpolator, but I am not sure how.

[21354-screen+shot+2014-01-29+at+2.17.21+pm.png|21354]

My code:

public var tube_picker = new Array(0,0,0,0,1);//Ration of 0 to 1 is the percentage of Strait to Curve
public var strait : GameObject;
public var curve : GameObject;
public var instatiate_position : Vector3 = Vector3.zero;
public var instatiate_rotation : Quaternion = Quaternion.identity;
public var tube_array = new Array();
public var starting_tube_length : int = 8;

public var spline_root : GameObject;

function Start () {
	//Set up the initial tube
	for(var tube_piece_number : int = 0; tube_piece_number < starting_tube_length; tube_piece_number++){
		var new_tube_piece = Instantiate(strait, instatiate_position, instatiate_rotation);
		var new_piece_out = new_tube_piece.transform.Find("Out");
		instatiate_position = new_piece_out.position;
		instatiate_rotation = new_piece_out.rotation;
		tube_array.Add(new_tube_piece);	
		//Set up next target for Spline
		var new_piece_in : Transform = new_tube_piece.transform.Find("In").transform; 
		new_piece_in.parent = spline_root.transform;	
	}
}

function Update () {
	if(Input.GetKeyDown("a")){//Set on button press to control the process for debugging
		var picker_index = Random.Range(0, tube_picker.length); //Randomly choose between Strait and Curved
		var picked_option =tube_picker[picker_index];
		var picked_tube = strait;
		if(picked_option == 1){
			picked_tube = curve;
		}
		var new_tube_piece = Instantiate(picked_tube, instatiate_position, instatiate_rotation);
		//Set up position and rotation for the next piece
		var new_piece_out = new_tube_piece.transform.Find("Out"); 
		instatiate_position = new_piece_out.position;
		instatiate_rotation = new_piece_out.rotation;
		tube_array.Add(new_tube_piece);
		//Set up next target for Spline
		var new_piece_in : Transform = new_tube_piece.transform.Find("In").transform; 
		new_piece_in.parent = spline_root.transform;
		//Destory oldest piece to keep asset count low
		/*var oldest_piece = tube_array[0];
		tube_array.RemoveAt(0);
		Destroy(oldest_piece);*/
	}
} 

After brief look at the code i found this

throw new System.Exception("Cannot add points after start");

So its most likely not good idea to do what you are trying to do.


Control points for the debug line are taken from transforms every OnGizmosDraw

But for the actual interpolation the transforms are only taken on Start()

Try to change line #134 of SplineController.cs from

SetupSplineInterpolator(mSplineInterp, mTransforms);

to

SetupSplineInterpolator(mSplineInterp, GetTransforms());