I am making a script to generate a spline dynamically; this part works, and the Spline is created and goes through the defined points smoothly.
However, my ultimate goal is to create a pipe (actually to have three concentric with different colour pipes) following this spline. But I cannot manage to create the extrude part. I am getting the error Spline Extrude does not have a valid SplineContainer set. even if I added my SplineExtrude to my SplineContainer. Here is my code:
foreach (string ppl in pplList)
{
// pipes is a list of empty GameObject.
pipes[ppl].transform.parent = transform;
pipes[ppl].name = "Spline-" + currentNodeNumber + "-" + nextNodeNumber + "_" + ppl;
var container = pipes[ppl].AddComponent<SplineContainer>();
var spline = container.Spline;
spline.Add(new BezierKnot(startNode.position), TangentMode.AutoSmooth);
spline.Add(new BezierKnot(new float3(0f, 2f, 0f)), TangentMode.AutoSmooth); // temp
spline.Add(new BezierKnot(endNode.position), TangentMode.AutoSmooth);
//var extrude = pipes[ppl].AddComponent<SplineExtrude>();
var extrude = container.AddComponent<SplineExtrude>();
extrude.Radius = 1;
extrude.SegmentsPerUnit = 20;
extrude.Sides = 20;
//SplineMesh.Extrude(spline, new Mesh(), 1, 20, 20, false);
break; // temp (testing only one pipe first)
}
}
I mostly based my code on the API documentation. But I couldn’t find an example about the Extrude part. How should I connect the SplineExtrude to the SplineContainer?
Thanks in advance.