Background
Background

Creating Splines for UMG, leveraging the internal drawing API

I created UMG Splines to draw editable curves inside UMG, Unreal’s UI authoring system, using Slate’s existing drawing functions. The project offered cubic Bézier and Hermite-style curves in 2D interface space.

A white UI curve changes shape as four coloured handle widgets are moved in the designer.
Moving the handle targets changes the curve in the designer.

This is an older project, and I’d revisit its design and code standards now. Past me also deserves a bonk for all those autos.

I kept point positions, colour and thickness together in a common data structure, with separate Slate and UMG bases for specialised behaviour. A cubic Bézier uses two endpoints and two control points; the Hermite option uses endpoints and tangent vectors, which describe how the curve leaves and approaches its ends.

Drawing APIs, shared data and Slate initialisation

The engine drawing functions are FSlateDrawElement::MakeCubicBezierSpline for the cubic Bézier and FSlateDrawElement::MakeSpline for the Hermite form.

The project’s abstract SSpline base derives from the engine’s SLeafWidget. The custom USpline supplies the UMG-facing wrapper through UWidget. These custom spline classes are separate from Unreal’s world-spline components.

I grouped points, colour and thickness in the project’s FSplineData structure. Concrete derived Slate widgets receive that data through their Construct function as a required argument, with named Slate arguments available for additional settings.

This split is the interface I chose. Slate’s argument-building machinery prepares those settings; Construct initialises the widget separately from its C++ constructor. Named arguments are not universally restricted to optional data.

One bend point, two handles

I wanted a simpler way to shape a curve than adjusting both cubic handles independently. The specialised widget takes one bend point, applies an offset, then places each handle halfway between that adjusted point and one endpoint.

A cyan connection between two circular widgets changes from straight to arched, then shows two coloured control handles and white construction lines.
The bend example reveals the two generated handles and their construction lines.

The midpoint rule is a shaping heuristic: a practical control for the appearance of the curve, with no guarantee of uniform curvature or spacing along it.

Let the container choose the bend

I expanded this with custom containers that divide the space around a centre into eight directional sectors. The container uses those sectors to drive bend settings for its splines.

A central circular widget and four surrounding widgets, with curved connections and radial debug lines dividing the space into sectors.
Container-driven connections, with debug lines marking the directional sectors.

The shown helper assumes a fixed centre of (250, 250). It is a layout-specific example; other container sizes, sector boundaries and degenerate cases need validation before reuse.

Sector angles and the direction-array index

The project’s custom USplineMathLibrary uses 45-degree sectors ordered east, southeast, south, southwest, west, northwest, north and northeast.

The helper returns a float even though the caller uses it as an array index. Its sector-selection rules were tied to this example; handling of the centre point and boundary angles remains unvalidated.

Working around designer handles

In the stock UE4 setup described here, I ran into restrictions when adding custom designer handles. My workaround passes handle widgets and their canvas through a custom node called from PreConstruct. I put the handle behaviour behind an interface so different spline types could reuse it.

PreConstruct executes the custom Set Spline Handles node before a Branch. Point 1 through Point 4 and Main Canvas feed the setter; Is Design Time feeds the later Branch condition.
The historical graph supplies four handle targets and their canvas to the custom Set Spline Handles node.

The setter runs before the Branch. Is Design Time controls only that later branch, so this graph does not establish editor-only execution, runtime handle removal or exclusion from packaged builds.

Handle positions come from cached geometry: each widget’s top-left is converted into the canvas’s local coordinates. Cached layout geometry can be out of date, and the original loop does not check point-array bounds. Valid widget pointers alone do not settle either issue.

The handle-to-canvas coordinate conversion

The custom ISHandle interface reads geometry from Slate widgets through SWidget::GetCachedGeometry(). It uses FGeometry::GetAbsolutePositionAtCoordinates with (0, 0) for the handle’s top-left, then FGeometry::AbsoluteToLocal to express that position relative to the canvas.

This historical extract omits the surrounding loop and pointer checks. It assumes usable cached geometry and an existing destination entry:

Data.Points[index] = AllocatedCanvasGeo.AbsoluteToLocal(
AnchorGeo.GetAbsolutePositionAtCoordinates({ 0.f, 0.f }));

The conversion does not itself validate layout timing, display scaling or widget lifetime. The original loop also assumes the points array has an entry for every handle.

My designer-extension contribution is retained as a historical reference. Its outcome and relevance to current Unreal versions remain unverified; current documentation for FDesignerExtension does not establish the old build’s behaviour.

Move over the bright dot and follow the line. P pauses. Escape closes the game.

Sigil Trace

Move over the sigil before time runs out.

Score0000
Spells00
Best on this browser0000
I · KINDLE SPELL 01
START

Trace the Sigil with your mouse

Start at the glowing dot and follow the line. No click needed.

or press Enter
Move your mouse onto the bright dot. No click needed.