04-09-2021, 01:17 AM
I hate to revive a pretty old thread, but I'm having the same issue (let me know if I should create a new thread about this). My code is as follows
I trigger this function from a custom script attached to a game object with a Curvy Spline component that exposes a button in the inspector (so not at runtime, just in the editor itself).
By digging into the source Curvy code it looks like SaveToScene is returning null due to createMesh not having any manageable resources. I apologize if this goes against the rules, but I'd just like to help point as far as I got:
in CreateMesh.cs
I've also tried replacing my code with the previous suggested snippets and ran into the same problem (using manual refreshes and all that). I'm using Unity 2020.2.0f1 and Curvy 7.1.4. I appreciate any advice that can be given.
Code:
public void GenerateColliderVolume() {
GameObject volumeCollider = new GameObject("Volume Collider");
volumeCollider.transform.parent = this.gameObject.transform;
CurvyGenerator generator = volumeCollider.AddComponent<CurvyGenerator>();
generator.ShowDebug = true;
generator.AutoRefresh = true;
InputSplinePath inputSplinePath = generator.AddModule<InputSplinePath>();
InputSplineShape inputSplineShape = generator.AddModule<InputSplineShape>();
BuildShapeExtrusion shapeExtrusion = generator.AddModule<BuildShapeExtrusion>();
BuildVolumeMesh volumeMesh = generator.AddModule<BuildVolumeMesh>();
CreateMesh createMesh = generator.AddModule<CreateMesh>();
inputSplinePath.Spline = mySpline; // this is just the Curvy Spline I've already created elsewhere
inputSplinePath.Path.LinkTo(shapeExtrusion.InPath);
CSCircle circle = inputSplineShape.gameObject.AddComponent<CSCircle>();
circle.Count = 4;
circle.Radius = 1;
inputSplineShape.Shape = circle.Spline;
inputSplineShape.OutShape.LinkTo(shapeExtrusion.InCross);
shapeExtrusion.OutVolume.LinkTo(volumeMesh.InVolume);
volumeMesh.OutVMesh.LinkTo(createMesh.InVMeshArray);
generator.Initialize(true);
GameObject finalCollider = createMesh.SaveToScene(null);
Debug.Log(finalCollider); // it's null
}
I trigger this function from a custom script attached to a game object with a Curvy Spline component that exposes a button in the inspector (so not at runtime, just in the editor itself).
Code:
[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor {
public override void OnInspectorGUI() {
MyScript myScript = (MyScript)target;
DrawDefaultInspector();
if (GUILayout.Button("Generate Collider Volume")) {
myScript.GenerateColliderVolume();
}
}
}
By digging into the source Curvy code it looks like SaveToScene is returning null due to createMesh not having any manageable resources. I apologize if this goes against the rules, but I'd just like to help point as far as I got:
in CreateMesh.cs
Code:
public GameObject SaveToScene(Transform parent = null) {
// SOME INTERNAL CODE
if (managedResources.Count == 0) {
Debug.Log("There's your problem");
return null;
}
// SOME MORE INTERNAL CODE
}
I've also tried replacing my code with the previous suggested snippets and ran into the same problem (using manual refreshes and all that). I'm using Unity 2020.2.0f1 and Curvy 7.1.4. I appreciate any advice that can be given.