Accessing Metadata from SpriteShapeController Point

Hello!

I am currently working on a project that utilizes the SpriteShapeController component to create procedurally generated terrain. I am using Unity 2022.3.19f1.

I’ve been trying to find a way to randomly assign the SpriteShape edge sprite via code. I noticed that if I manually create points in my scene, I can assign sprite variants via the editor, as seen below -

However, I haven’t been successful in finding a way to do this through code. I found SpriteShapeMetaData.cs, which felt promising, but there doesn’t seem to be a way to access and assign individual points during or after their creation.

Below is a code snippet from my terrain generation code.

        //shape = My SpriteShape
        SpriteShapeMetaData _ssMD = shape.GetComponent<SpriteShapeMetaData>();
        for (int i = 0; i < pointCount; i++){
          shape.spline.SetTangentMode(i+2,ShapeTangentMode.Continuous);
          //Current attempt to assign the spriteIndex variable with a random range (0-5) (sourced from the SpriteShape)
          //Doesn't address the issue of assigning the spriteIndex for every point, though
          _ssMD.spriteIndex = (uint) UnityEngine.Random.Range(0, 5);
          shape.spline.SetLeftTangent(i+2,new Vector3(-2,0,0));
          shape.spline.SetRightTangent(i+2,new Vector3(2,0,0));
        }

If anyone has any tips or ideas on how to achieve this, I’d greatly appreciate it. Thank you!

Bumping - So far I haven’t had much luck iterating on my current solution!

To set sprite-index at a specific point on the SpriteShapeController’s spline, please use
Spline’s SetSpriteIndex
as described here: Class Spline | 2D SpriteShape | 9.0.2 (unity3d.com)