04-09-2021, 09:13 AM
Hi
Here is a version of MyScript that has not the issue:
There are two changes:
- calling Refresh() on circle
- saving the mesh in an OnRefresh event listener
I kept the generator.Initialize, even if it is not necessary in this case.
Sorry for the complications. The generator's current initialization process makes it span on possibly multiple frames, so a straight forward code like yours does not always work. Making the generators initialize in one frame is a task in my todo list, but I have to admit that it isn't very high on the list for now, due to the amount of work it involves, and the comparatively low benefits compared to other items on that list. But it should eventually be done.
Thanks for your patience, and have a nice day
Here is a version of MyScript that has not the issue:
Code:
using FluffyUnderware.Curvy;
using FluffyUnderware.Curvy.Generator;
using FluffyUnderware.Curvy.Generator.Modules;
using FluffyUnderware.Curvy.Shapes;
using UnityEngine;
public class MyScript : MonoBehaviour
{
public CurvySpline mySpline;
private CreateMesh createMeshModule;
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>();
createMeshModule = 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;
circle.Refresh();
inputSplineShape.Shape = circle.Spline;
inputSplineShape.OutShape.LinkTo(shapeExtrusion.InCross);
shapeExtrusion.OutVolume.LinkTo(volumeMesh.InVolume);
volumeMesh.OutVMesh.LinkTo(createMeshModule.InVMeshArray);
generator.Initialize(true);
generator.OnRefresh.AddListener(OnGeneratorRefreshed);
}
private void OnGeneratorRefreshed(CurvyCGEventArgs aguments)
{
aguments.Generator.OnRefresh.RemoveListener(OnGeneratorRefreshed);
GameObject finalCollider = createMeshModule.SaveToScene(null);
Debug.Log(finalCollider); // it's null
}
}
There are two changes:
- calling Refresh() on circle
- saving the mesh in an OnRefresh event listener
I kept the generator.Initialize, even if it is not necessary in this case.
Sorry for the complications. The generator's current initialization process makes it span on possibly multiple frames, so a straight forward code like yours does not always work. Making the generators initialize in one frame is a task in my todo list, but I have to admit that it isn't very high on the list for now, due to the amount of work it involves, and the comparatively low benefits compared to other items on that list. But it should eventually be done.
Thanks for your patience, and 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.