How to access additional Spline Container properties?

I just started messing around with the Splines package and I can’t figure out how to access the additional properties of a Spline Container: Int Data, Float Data, Float4 Data, Object Data. For example, it looks like I should be able to name and access Int Data properties to reference specific knots but I can’t find out how from the docs, looking at the code, or from asking Unity Muse or ChatGPT.

Maybe y’all can point me in a direction? I would expect I could access the Int Data and pass in the key and have the correct knot returned like you would with a dictionary but cannot find a way to do so. Maybe I’m using this incorrectly? But also I can’t find information on how to use the other properties either. The Object Data property seems particularly interesting as well.

Here’s my inspector:

1 Like

I am searching for the same answer since a hour, but I found nothing useful in the documentation.

I’m not sure, but maybe it’s worth checking out
EmbeddedSplineData

Here’s an example of how I use spline data to control my camera’s FOV.

I named my data “CameraFOV”. I chose to index by “Knot Index”, so each of my data points is associated with a specific Knot. I input my desired FOV for each knot in the spline.

Then in code, I get the nearest spline point to my player, and evaluate the embedded data at that point using normalized distance along the spline.

// get the player's position local to the spline
Vector3 splineLocalPoint = _currentPathSpline.transform.InverseTransformPoint(_playerTransform.position);

float nearest = float.MaxValue;
float nearestNormalizedDistance = 0;

// get the nearest spline point to the player by checking the player's distance to each spline
for (int i = 0; i < _currentPathSpline.Splines.Count; i++)
{
    Spline spline = _currentPathSpline.Splines[i];
    float distance = SplineUtility.GetNearestPoint(spline, splineLocalPoint, out float3 splinePoint, out float t);
    if(distance < nearest)
    {
        nearest = distance;
        _currentSpline = spline;
        _nearestSplinePoint = splinePoint;
        nearestNormalizedDistance = t;
    }
}

// my default FOV
float zoom = 15f;

// attempt to get data "CameraFOV" stored in the spline
if(_currentSpline.TryGetFloatData("CameraFOV", out SplineData<float> data))
{
    // convert from normalized distance to knot index
    // (halfway between knot 1 and 2 would return 1.5)
    float index = _currentSpline.ConvertIndexUnit(nearestNormalizedDistance, PathIndexUnit.Normalized, PathIndexUnit.Knot);

    // get the data at the knot index, which is interpolated between knots using lerp
    zoom = data.Evaluate(_currentSpline, index, PathIndexUnit.Knot, InterpolatorUtility.LerpFloat);
}

// apply the data 
_currentVirtualCamera.m_Lens.FieldOfView = zoom;

“_currentPathSpline” is my SplineContainer.

Hope that helps.

2 Likes