# Which algorithm is used for spline components in UE4?

**URL:** <https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817>\
**Category:** Community & Industry Discussion\
**Tags:** math, unreal-engine, Spline, question\
**Created:** [November 8, 2015, 9:29am UTC](https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817 "2015-11-08T09:29:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a49f03e3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a49f03e3](https://forums.unrealengine.com/u/anonymous_user_a49f03e3)\
**Post date:** [November 8, 2015, 9:29am UTC](https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817/1 "2015-11-08T09:29:37Z")

</div>

In the pursuit of solving my bigger problem with UE4 splines, I decided to do some math computation myself. I quickly realized, that I don’t know which algorithm is actually being used by the engine to draw the splines.

A quick search showed me the exactly this question being posted on the UE forums:

> **[\[Question to developers\] Which algorithm is used for spline components in UE4?](https://forums.unrealengine.com/showthread.php?84858-Question-to-developers-Which-algorithm-is-used-for-spline-components-in-UE4)**
>
> I hope that one of the developers would be able to share information on how current implementation of spline components works under the hood. More specifically what kind of class of curves is used - is it one of the Bézier, Cubic Hermite or maybe...

to which TheJamsh reports that they are using Cubic Bezier by default.  
However, through experimentation this cannot be true!

Consider the following simple experiment: put control points p0, p1, p2, p3 in a square and draw a Cubic Bezier spline S. Using a simple DeCasteljau algorithm you can conclude that the curve will reach 75% height of the square, exactly at S(0.5).

![65996-paint.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/6/2/7624bff6a686d7483b5643e188cd1eade3c61857.png)

The built-in spline tool of Paint also agrees with it 🙂

In UE4 you don’t specify points p1 and p2, but use tangents t0, t3 at points p0, p3 respectively. I assume that t0 = p1-2 and t3 = p3-p2. However, in UE4 (using the Unreal Tournament version), I get a different result:

![65997-spline+square+ue4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/b/6fbda5a771ef736e51b058df942dd2903a63e657.png)

The resulting spline is much shorter, as if the tangents were dampened somehow.  
Which brings me back to the original question - what is the math driving the splines in UE4?  
Or maybe it is intended to be a cubic bezier but there is some bug lurking in the formula?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [November 8, 2015, 4:47pm UTC](https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817/2 "2015-11-08T16:47:41Z")

</div>

Try checking code for yourself:

[https://github.com/EpicGames/UnrealEngine/blob/a27ad66f0a075f3b74ef8f68a4b2b0da4882425e/Engine/Source/Runtime/Engine/Private/Components/SplineComponent.cpp](https://github.com/EpicGames/UnrealEngine/blob/a27ad66f0a075f3b74ef8f68a4b2b0da4882425e/Engine/Source/Runtime/Engine/Private/Components/SplineComponent.cpp)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a49f03e3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a49f03e3](https://forums.unrealengine.com/u/anonymous_user_a49f03e3)\
**Post date:** [November 9, 2015, 9:38am UTC](https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817/3 "2015-11-09T09:38:58Z")

</div>

Unfortunately, I have problems accessing that code. I added my git unsername to the profile setting, but I still get error 404 as if the file never even existed.

---

<div class="post-metadata">

**Author:** ![Benergy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Benergy](https://forums.unrealengine.com/u/Benergy)\
**Post date:** [April 9, 2017, 1:07pm UTC](https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817/4 "2017-04-09T13:07:43Z")

</div>

I stumbled across this question because I had the same and looked it up myself. I know this question is kind of outdated, but I want to post the answer anyway in case someone else needs this to know.

I looked into the source code (4.14) of the spline component and saw that the interpolation is done by the template function CubicInterp() in the header UnrealMathUtility.h . This function looks like this:

```
template< class T, class U > 
static FORCEINLINE_DEBUGGABLE T CubicInterp( const T& P0, const T& T0, const T& P1, const T& T1, const U& A )
{
	const float A2 = A * A;
	const float A3 = A2 * A;

	return (T)(((2*A3)-(3*A2)+1) * P0) + ((A3-(2*A2)+A) * T0) + ((A3-A2) * T1) + (((-2*A3)+(3*A2)) * P1);
}

```

where P0 and P1 are start and end point and T0 and T1 are their tangents.

I looked this formula up at [Bézier curve - Wikipedia](https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves) . There you don’t find the formula with tangents, but with two intermediate points, which can be converted into P0+T0 and P1-T1. After simplifying the formula and comparing it to the function above from the source code, the tangents need to be multiplied by 3 to match the formula from wikipedia. You can see this by multiplying your tangents _manually_ by 3 and then you get the expected result for the original tangents.

I don’t know if this is really a bug or done on purpose, but nevertheless, now you know it 🙂

---

<div class="post-metadata">

**Author:** ![Cimmerick](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cimmerick](https://forums.unrealengine.com/u/Cimmerick)\
**Post date:** [January 13, 2025, 10:46am UTC](https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817/5 "2025-01-13T10:46:18Z")

</div>

Just want to say thanks for this! Was having some difficulty finding out why converting an Unreal spline to SVG was giving weird results with the handles.

---

<div class="post-metadata">

**Author:** ![ckf104](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ckf104](https://forums.unrealengine.com/u/ckf104)\
**Post date:** [April 14, 2025, 7:05am UTC](https://forums.unrealengine.com/t/which-algorithm-is-used-for-spline-components-in-ue4/337817/6 "2025-04-14T07:05:07Z")

</div>

This is cubic hermite spline. But if `EInterpCurveMode` is `CIM_CurveAuto`, unreal will use catmull-rom spline.
