Search Unity

Feedback SpriteShape can't set all spline positions without error

Discussion in '2D' started by CDF, Jul 30, 2020.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    So I'm creating a utility to align the transform position (pivot) to the bounds of a sprite shape (left, right, bottom and top).

    In order to do this I need to loop over positions on spline and translate them.
    The issue is that during the loop, positions might temporarily be in the same location. Like when aligning top -> bottom.

    This error occurs:

    Code (CSharp):
    1. ArgumentException: Internal error: Point too close to neighbor
    2. UnityEngine.U2D.Spline.SetPosition (System.Int32 index, UnityEngine.Vector3 point) (at Library/PackageCache/com.unity.2d.spriteshape@4.1.2/Runtime/Spline.cs:90)
    But if the loop could continue, the end result would be a valid spline!
    It would be very helpful to just access the controlPoints directly and modify, like so:

    var cp = spline.GetControlPoint(index)
    cp.position = somePosition;

    thus avoiding the "IsPositionValid" call.

    I realize you could put the spline into an invalid state, but I promise I won't ;)

    My only option currently is to use Reflection :(