New: 36 free tools for Unreal Engine and Unity developers.Try them →

Smooth Movement with Easing in Unity and Unreal (with Code)

Animate UI, doors, cameras and pickups smoothly with easing functions: copy-paste C# for Unity and C++ for Unreal Engine, plus mistakes to avoid.

In this article
  1. The pattern
  2. Unity (C#)
  3. Unreal Engine (C++)
  4. Get the easing functions
  5. Common mistakes
  6. Summary
  7. FAQ

A door that slides open with a soft landing, a menu that pops in with a tiny overshoot, a coin that bounces into place: all of these use the same simple pattern. Once you know it, you can animate almost anything smoothly in a few lines of code. If you are new to easing, first read Easing Functions for Game Developers to choose the right curve.

The pattern

t      = clamp(elapsed / duration, 0, 1)   // linear progress
eased  = Ease(t)                            // shaped progress
value  = Lerp(start, end, eased)            // apply it

That is all. Change Ease and the same animation feels completely different.

Unity (C#)

using System.Collections;
using UnityEngine;

public class SlideIn : MonoBehaviour
{
    public Vector3 offset = new Vector3(0, -2, 0);
    public float duration = 0.35f;

    static float EaseOutBack(float t)
    {
        const float c1 = 1.70158f, c3 = c1 + 1f;
        return 1f + c3 * Mathf.Pow(t - 1f, 3f) + c1 * Mathf.Pow(t - 1f, 2f);
    }

    IEnumerator Start()
    {
        Vector3 end = transform.localPosition;
        Vector3 start = end + offset;
        for (float elapsed = 0f; elapsed < duration; elapsed += Time.deltaTime)
        {
            float t = Mathf.Clamp01(elapsed / duration);
            transform.localPosition = Vector3.LerpUnclamped(start, end, EaseOutBack(t));
            yield return null;
        }
        transform.localPosition = end;
    }
}

Notes:

  • LerpUnclamped keeps the overshoot of Back and Elastic easings. Vector3.Lerp would clamp it away.
  • Set the final value after the loop so it always lands exactly on the target.
  • For UI that should animate while the game is paused, use Time.unscaledDeltaTime.

Unreal Engine (C++)

// Header
float Elapsed = 0.f;
float Duration = 0.35f;
FVector StartLocation, EndLocation;
bool bMoving = false;

static float EaseOutCubic(float T)
{
    return 1.f - FMath::Pow(1.f - T, 3.f);
}

// Call this to start the movement
void AMyDoor::Open()
{
    StartLocation = GetActorLocation();
    EndLocation = StartLocation + FVector(0.f, 0.f, 250.f);
    Elapsed = 0.f;
    bMoving = true;
}

void AMyDoor::Tick(float DeltaSeconds)
{
    Super::Tick(DeltaSeconds);
    if (!bMoving) return;
    Elapsed += DeltaSeconds;
    const float T = FMath::Clamp(Elapsed / Duration, 0.f, 1.f);
    SetActorLocation(FMath::Lerp(StartLocation, EndLocation, EaseOutCubic(T)));
    if (T >= 1.f) bMoving = false;
}

Notes:

  • FMath::Lerp does not clamp, so overshooting easings work.
  • Disable ticking when the actor is idle if you have many of them (SetActorTickEnabled(false)).

In Blueprint

  • The Ease node takes an alpha and an easing type (such as Ease In Out or Exponential).
  • A Timeline with a float curve lets you draw any curve visually and drives a Lerp node every frame.

Get the easing functions

Writing all 31 standard easings by hand is tedious. The free Easing Functions & Curves tool previews every easing live and gives you copy-ready code for each, or one file with all of them: Easing.cs for Unity, Easing.h for Unreal or easing.js for the web. They use the standard Robert Penner formulas, so names match tweening libraries.

Common mistakes

  • Lerping from the current position every frame (Lerp(current, target, 0.1)): this gives an exponential slow-down that never quite arrives and depends on frame rate. Store the start value instead.
  • Forgetting to clamp t, so the animation keeps going past the end.
  • Clamped lerps with overshooting easings, which cut off the bounce.
  • Animations that are too long. For UI, 150–400 ms usually feels right.

Summary

  • t = elapsed / duration, eased = Ease(t), value = Lerp(start, end, eased).
  • Unity: coroutine or Update with LerpUnclamped.
  • Unreal: Tick with FMath::Lerp, or Ease node / Timeline in Blueprint.
  • Store the start value, clamp t and keep UI animations short.

Frequently asked questions

How do I use an easing function in Unity?

Compute t = elapsed / duration (clamped to 0–1), call your easing function on t, and use Vector3.LerpUnclamped(start, end, easedT). Run it in a coroutine or in Update.

How do I use an easing function in Unreal Engine?

In C++, accumulate DeltaTime in Tick, compute the alpha, apply the easing function and pass it to FMath::Lerp. In Blueprint, use the Ease node or a Timeline with a curve asset.

Why use LerpUnclamped in Unity?

Easings like easeOutBack and easeOutElastic go slightly past 1 to overshoot. Vector3.Lerp clamps t to 0–1 and cuts the overshoot off; LerpUnclamped keeps it.

Should I use a tween library instead?

Tween libraries such as DOTween (Unity) are great for many UI animations. Knowing the underlying pattern still helps for gameplay code, custom curves and engines without a tween library.

  • #animation
  • #unity
  • #unreal engine
  • #code
Written by Renish

Indie Unreal Engine developer and founder of Tvashta Studio. Builds the Shopping Simulator Kit plugin in UE5 C++ and the free tools on this site, and writes these guides from that work for Unreal Engine and Unity developers. More about the studio.

Related articles

All articles →