Roblox UtilitiesDevlHub Roblox Documentation

Class

Path2D

Inherits
GuiBase › Instance › Object
Memory category
Instances

Represents a 2D cubic spline path that renders a stroked curve under any GuiObject.

Path2D is a UI instance that represents a 2D spline. It can be placed under any GuiObject and be edited directly in the viewport using built‑in tooling. Path2D stores control points and exposes methods to sample positions along the curve, enabling curved UI layouts, path‑based animations, and interactive tools like graph editors and visual effects.

See the 2D paths guide for more information and usage examples.

Properties 7#

ClosedbooleanConnects the first and last control points when enabled.ReadSafe
Color3Color3Determines the color of the Path2D.ReadSafe
SelectedControlPointintIndex of the currently selected Path2DControlPoint.Read: RobloxScriptSecurityWrite: RobloxScriptSecurityReadSafeNotReplicated
SelectedControlPointDataPath2DControlPointPath2DControlPoint data type representing the currently selected control point.Read: RobloxScriptSecurityWrite: RobloxScriptSecurityReadSafeNotReplicated
ThicknessfloatDetermines how thick the Path2D path is.ReadSafe
VisiblebooleanDetermines if the Path2D path is rendered or not.ReadSafe
ZIndexintDetermines the order in which a Path2D path renders relative to other GUIs.ReadSafe

Closed: boolean#

ReadSafe

When set to true, the path forms a closed loop by connecting the last control point back to the first. The closure only takes effect when the path has at least 3 control points. Defaults to false.

Color3: Color3#

ReadSafe

Determines the stroke color used to render the Path2D. Defaults to [0, 0, 0] (black). A child UIGradient can override the solid color with a gradient fill.

SelectedControlPoint: int#

NotReplicatedRead: RobloxScriptSecurityWrite: RobloxScriptSecurityReadSafe

The 1-based index of the currently selected control point. Defaults to 1 and is clamped to the range [1, number of control points]. Changing this value updates Path2D.SelectedControlPointData to reflect the control point at the new index.

SelectedControlPointData: Path2DControlPoint#

NotReplicatedRead: RobloxScriptSecurityWrite: RobloxScriptSecurityReadSafe

A read-only computed property that returns the Path2DControlPoint at the index specified by Path2D.SelectedControlPoint. If the path has no control points, returns a default-constructed Path2DControlPoint (position and tangents all at {0, 0, 0, 0}).

Thickness: float#

ReadSafe

Determines the stroke width of the Path2D in pixels. Defaults to 1 and is clamped to the range [0, 100].

Visible: boolean#

ReadSafe

Determines if the Path2D path is rendered or not. When false, the path will not render. However, any modifications to the control points will update correctly, ensuring that querying data will have the correct info.

ZIndex: int#

ReadSafe

Determines the order in which a Path2D path renders relative to other GUIs. Works the same as GuiObject.ZIndex but does not interact with layout order in any way.

Methods 13#

GetBoundingRectReturns the bounding size for the Path2D.
GetControlPointReturns the Path2DControlPoint for a given index.
GetControlPointsReturns all the Path2DControlPoints for the Path2D.
GetLengthReturns the length of the Path2D.
GetMaxControlPointsReturns the maximum allowed number of control points.
GetPositionOnCurveReturns the position at a given value in parameter space.
GetPositionOnCurveArcLengthReturns the position at a given value in arc length space.
GetTangentOnCurveReturns the tangent at a given value in parameter space.
GetTangentOnCurveArcLengthReturns the tangent at a given value in arc length space.
InsertControlPointInserts a new control point at a given index.
RemoveControlPointRemoves a control at the given index.
SetControlPointsSets all the control points to the specified array, replacing all existing points with new ones.
UpdateControlPointUpdates a control point at the given index.

GetBoundingRect(): Rect#

Returns the Rect bounding size for the Path2D. This is computed based on the control points and is not modifiable outside of changing the control point data.

Returns
  • Rect — The Rect bounding box that encloses the path, expanded by its rendered thickness.

GetControlPoint(index: int): Path2DControlPoint#

Returns the Path2DControlPoint for a given index. If the index is out of bounds, this method will throw an error.

NameTypeDefaultDescription
indexintThe 1-based index of the control point to return.
Returns

GetControlPoints(): Array#

Returns a table of all the Path2DControlPoints for the Path2D.

Returns

GetLength(): float#

Returns the length of the Path2D. This function can be expensive if called too frequently.

Returns
  • float — The total length of the path.

GetMaxControlPoints(): int#

Returns 100, the hard upper limit on the number of control points a Path2D can contain. Attempting to add points beyond this limit via Path2D:InsertControlPoint() or Path2D:SetControlPoints() throws an error.

Returns
  • int — The maximum number of control points a Path2D supports.

GetPositionOnCurve(t: float): UDim2#

Returns the 2D UDim2 position at a given t value between 0 and 1 (inclusive), representing the parameter space result of querying the spline. The values will be more tightly packed near bends and wider apart in straighter segments; see GetPositionOnCurveArcLength() for even spacing results.

Throws an error if the Path2D has less than two control points.

NameTypeDefaultDescription
tfloatThe value to query the Path2D at.
Returns
  • UDim2 — The position in parameter space.

GetPositionOnCurveArcLength(t: float): UDim2#

Returns the 2D UDim2 position at a given t value between 0 and 1 (inclusive), representing the arc length space result of querying the spline. The values will be evenly spaced along the spline; see GetPositionOnCurve() for parameter spacing results.

Throws an error if the Path2D has less than two control points.

NameTypeDefaultDescription
tfloatThe value to query the Path2D at.
Returns
  • UDim2 — The position in arc length space.

GetTangentOnCurve(t: float): Vector2#

Returns the tangent at a given t value in parameter space where t is a value between 0 and 1 (inclusive). Throws an error if the Path2D has less than two control points.

NameTypeDefaultDescription
tfloatThe value to query the Path2D at.
Returns
  • Vector2 — The tangent in parameter space.

GetTangentOnCurveArcLength(t: float): Vector2#

Returns the tangent at a given t value in arc length space where t is a value between 0 and 1 (inclusive). Throws an error if the Path2D has less than two control points.

NameTypeDefaultDescription
tfloatThe value to query the Path2D at.
Returns
  • Vector2 — The tangent in arc length space.

InsertControlPoint(index: int, point: Path2DControlPoint): ()#

Inserts a new Path2DControlPoint at a given index. Throws a warning if the index is out of bounds or if you're trying to add control points past the limit of 50.

NameTypeDefaultDescription
indexintThe index to insert at.
pointPath2DControlPointThe control point to insert.
Returns
  • ()

RemoveControlPoint(index: int): ()#

Removes a control point at the given index. Throws a warning if the index is out of bounds.

NameTypeDefaultDescription
indexintThe index to remove at.
Returns
  • ()

SetControlPoints(controlPoints: Array): ()#

Sets all the control points to the specified array, replacing all existing points with new ones. Throws a warning if there are more than 50 points in the controlPoints array.

NameTypeDefaultDescription
controlPointsArrayThe new list of control points to set.
Returns
  • ()

UpdateControlPoint(index: int, point: Path2DControlPoint): ()#

Updates the control point at the given index. Throws a warning if the index is out of range.

NameTypeDefaultDescription
indexintThe control point index to update.
pointPath2DControlPointThe new Path2DControlPoint value to store at the index.
Returns
  • ()

Events 1#

ControlPointChangedFires any time control points change.

ControlPointChanged()#

Fires whenever the path's control-point data is mutated. This includes calls to Path2D:SetControlPoints(), Path2D:InsertControlPoint(), Path2D:UpdateControlPoint(), and Path2D:RemoveControlPoint(). Does not fire for changes to visual properties such as Path2D.Color3 or Path2D.Thickness.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed