My program saves levels by putting all the gameobject data into serializable classes and saving that to a JSON file. It then loads levels by reading that JSON. I want to include official Unity splines in my levels, and where I'm stuck is saving the data from Spline Container. From what I can tell, it has a collection of Knots, which I think I can just store a vector3 for position for each since I'll keep them on "auto", but I'm not sure what else I need to store, or how I can get the information I need from the Spline Container. I've been reading the Spline documentation, but I still don't fully understand the data structures and interfaces involved
#Reading data from splines and putting data in new spline
1 messages · Page 1 of 1 (latest)
SplineContainer contains a Spline object, it is not the container for the spline data as might be assumed by the name. The data of the curve is stored in the Spline itself which can be accessed via SplineContainer.Spline. Since Spline seems to be serializable, you should be able to just serialize that as is.
If you wanted to manually serialize the Spline, all you would need to save would be its knots and whether the spline is closed (loops from start to end). Spline.ToArray() can be used to retrieve the knots and Spline(array, closed) constructor may be used to construct the spline back. BezierKnot seems to already be serializable, so there shouldn't be too much trouble with it. Those are made of couple vectors and a quaternion
SplineContainer should also be sort of serializable though it is meant to be serialized like other components, together with a scene/prefab. Assuming that you are creating the splines in code, serializing SplineContainer.Spline should be the way to go. If not, then you should specify how you are creating the splines and why you need to store them in JSON.
Since the bezier connections are on "auto", you should be able to store only the positions of the connections and reconstruct rest somehow in case you want to reduce the serialized sizes (each knot has total of 13 floats when 3 would do). I couldn't find the right tool for that by quick glance. Constructing the knots from the constructor that only takes single float3 and adding them to the Spline one by one could work, I don't know