Sometimes you want to store additional information to your spline, e.g. a max speed or other track information for your racing track, additional Curvy Generator data etc..

This is done by creating your own Metadata classes and attaching them to Control Points. You then can use Curvy Splines' API to access that data.

When assigning a Metadata to a Control Point, the Metadata's value is applied to the segment starting from said Control Point until the next one. When there is no Metadata interpolation, the value of the Metadata will suddenlty change one you reach the next Control Point. Sometimes, you want that value to be gradually interpolated between the two Control Points. That's when interpolatable Metadata comes into play.

Create a new MonoBehaviour that inherits from one of the following classes:

  • CurvyMetadataBase: Base class for all Metadata classes.
  • CurvyInterpolatableMetadataBase<T>: Base class for Metadata classes that support interpolation. This class is abstract, which means that you will need to implement its abstract members, namely the MetaDataValue getter and the Interpolate method.

Here is an example (used by the Metadata example scene) that provides a simple float value that can be interpolated:

namespace FluffyUnderware.Curvy.Examples
    public class HeightMetadata : CurvyInterpolatableMetadataBase<float>
        [RangeEx(0, 1, Slider = true)]
        float m_Height;
        public override float MetaDataValue
            get { return m_Height; }
        public override float Interpolate(CurvyInterpolatableMetadataBase<float> nextMetadata, float interpolationTime)
            return (nextMetadata != null) ? Mathf.Lerp(MetaDataValue, nextMetadata.MetaDataValue, interpolationTime) : MetaDataValue;

As Metadata classes are regular MonoBehaviours, simply add them to the desired Control Points using the Component menu.

You can access Metadata from Splines and from Control Points using the following API members:

  • GetMetadata<T>: Method that gets the Metadata class itself, of type T
  • GetInterpolatedMetadata<T, U>: Method that gets interpolated data of type U from Metadata class T
  • MetaDataSet: Property that gets a set of all attached Metadata (Curvy Spline Segment only)

For example, the MetadataController script from the example scene mentioned above uses the following code to access the height value:

float height = Spline.GetInterpolatedMetadata<HeightMetadata,float>(RelativePosition);