Tweening

1. Understanding the naming convention

Prefix

Behavior

Animation curve

In

Starts slowly, then accelerates

Slow → Fast

Out

Starts quickly, then decelerates

Fast → Slow

InOut

Starts slowly, accelerates, then slows down

Slow → Fast → Slow

Easing family

In

Out

InOut

Description

Linear

—

—

—

Constant speed throughout the animation.

Sine

InSine

OutSine

InOutSine

Gentle, smooth acceleration and deceleration.

Quad

InQuad

OutQuad

InOutQuad

Mild acceleration and deceleration.

Cubic

InCubic

OutCubic

InOutCubic

Stronger acceleration and deceleration than Quad.

Quart

InQuart

OutQuart

InOutQuart

More pronounced acceleration and deceleration.

Quint

InQuint

OutQuint

InOutQuint

Very pronounced acceleration and deceleration.

Expo

InExpo

OutExpo

InOutExpo

Exponential acceleration and deceleration.

Circ

InCirc

OutCirc

InOutCirc

Circular-style easing with a pronounced speed change.

Back

InBack

OutBack

InOutBack

Pulls backward or overshoots the target before settling.

Elastic

InElastic

OutElastic

InOutElastic

Spring-like movement with oscillation.

Bounce

InBounce

OutBounce

InOutBounce

Simulates bouncing movement at the beginning, end, or both.


2. Special easing functions

DOTween also documents four special Flash easing functions.

Easing

Behavior

Flash

Creates a flashing effect during the tween.

InFlash

Applies the flashing effect with an ease-in pattern.

OutFlash

Applies the flashing effect with an ease-out pattern.

InOutFlash

Applies the flashing effect with an ease-in-out pattern.



3. Starting, Stopping, and Controlling Tweens


Concept

What you'll learn

Kill()

Permanently stop an active tween

Pause()

Temporarily stop an animation

Play()

Resume a paused animation

Restart()

Start an animation again from the beginning

Rewind()

Return to the starting state and pauses it

IsPlaying()

Check whether a tween is playing

IsComplete()

Check whether a tween has finished

SetAutoKill()

Control what happens when a tween finishes


Setting

Behavior

SetAutoKill(true)

Automatically removes tween after completion

SetAutoKill(false)

Keeps tween available after completion

When you intend to reuse a tween with Restart(), Rewind(), or other control methods after it finishes, use SetAutoKill(false).


This is particularly useful for UI animations that happen repeatedly.


4. Complete Sequence Reference Chart

Save this table in your notes.

Method

Purpose

Example

Append()

Adds tween to the end

seq.Append(tween)

Join()

Plays alongside the last inserted tween

seq.Join(tween)

Insert()

Starts tween at a specific time

seq.Insert(0.5f, tween)

Prepend()

Adds tween to beginning

seq.Prepend(tween)

AppendInterval()

Adds a pause for the tween

seq.AppendInterval(1f)

PrependInterval()

Adds a pause at the beginning

seq.PrependInterval(1f)

AppendCallback()

Executes code at the end

seq.AppendCallback(() => Debug.Log("Done"))

InsertCallback()

Executes code at a specific time

seq.InsertCallback(1f, callback)

PrependCallback()

Executes code at the beginning

seq.PrependCallback(callback)


5. AppendCallback()

AppendCallback() lets you execute a piece of C# code at a specific point in the sequence.

For example:

Sequence mySequence = DOTween.Sequence();

mySequence.Append(transform.DOScale(1.5f, 1f));

mySequence.AppendCallback(() =>
{
    Debug.Log("Scaling finished!");
});

mySequence.Append(transform.DOScale(1f, 1f));

The sequence now does this:

  1. Scale up.

  2. Print "Scaling finished!" in the Console.

  3. Scale back down.

The callback itself doesn't animate anything. It simply executes code when the sequence reaches that point.

This opens up more possibilities for game development:

  • Open a menu, then enable its buttons.

  • Play a sound when a button animation finishes.

  • Trigger an enemy attack after an animation.

  • Display text after a UI transition.

  • Execute gameplay logic at specific animation milestones.

6: Callbacks and Events

Concept

What you'll learn

Callback

Execute code during an animation

OnStart()

Execute code when a tween starts

OnPlay()

Execute code when a tween begins or resumes playing

OnUpdate()

Execute code as a tween updates

OnComplete()

Execute code when a tween finishes

OnKill()

Execute code when a tween is killed

AppendCallback()

Execute code at a specific point in a sequence

InsertCallback()

Execute code at a specific timeline position

OnRewind()

When the tween is rewound

OnStepComplete()

Every time one loop cycle completes


OnStart() executes only on the first start. Resuming a paused tween does not trigger it again.

OnPlay() executes whenever the tween enters the playing state, including when it resumes from being paused.


using UnityEngine;
using DG.Tweening;

public class TweenCallbacks : MonoBehaviour
{
    void Start()
    {
        mySequence.Join(transform.DORotateQuaternion(origRot, 1f)).SetEase(Ease.Linear).SetAutoKill(false)
        .OnComplete(() => Debug.Log("Animation Has Been Complete"));
    }
}
  • OnComplete() tells DOTween when to execute the callback.

  • () => is a C# lambda expression.

  • The code inside { } is what gets executed.

  • The callback runs when the tween reaches completion.


AppendCallback()

AppendCallback() executes code at the end of the current sequence timeline.

Example:

Sequence sequence = DOTween.Sequence();

sequence.Append(transform.DOScale(1.5f, 1f));

sequence.AppendCallback(() =>
{
    Debug.Log("Scaling finished!");
});

sequence.Append(transform.DOScale(1f, 1f));

Here's the execution order:

Sequence timeline

  1. Scale up

    0–1 second

  2. AppendCallback()

    Prints "Scaling finished!" at 1 second.

  3. Scale down

    1–2 seconds


InsertCallback()

InsertCallback() works similarly, except you specify the exact time when you want the code to execute.

The structure:

sequence.InsertCallback(timePosition, callback);

Example:

Sequence sequence = DOTween.Sequence();

sequence.Append(transform.DOMoveX(5f, 2f));

sequence.InsertCallback(1f, () =>
{
    Debug.Log("One second has passed!");
});

What's happening?

  • The movement begins at 0 seconds.

  • At 1 second, the callback executes.

  • The movement continues until 2 seconds.

You can execute code while another animation is still running.



Using Named Methods Instead of Lambdas

You don't always have to put all your code inside a callback.

You can call an existing method instead.

For example:

void Start()
{
    transform.DOScale(1.5f, 2f)
        .OnComplete(AnimationFinished);
}

void AnimationFinished()
{
    Debug.Log("Animation finished!");
}

Compare the two approaches:

Lambda approach:

.OnComplete(() =>
{
    Debug.Log("Finished!");
});

Named method approach:

.OnComplete(AnimationFinished);

Both work. Use lambdas for small pieces of code and named methods when you have more logic to execute or want to reuse that logic.


7.Loops & Delays

Concept

What you'll learn

SetLoops()

Repeat an animation

LoopType.Restart

Start over after each loop

LoopType.Yoyo

Play forward and backward

LoopType.Incremental

Continue increasing the target value

SetDelay()

Delay the beginning of a tween

AppendInterval()

Add a pause inside a sequence

Infinite loops

Repeat an animation indefinitely

Loop callbacks

Detect when individual loops finish


SetLoops()

Let's start with the basic concept.

In DOTween, SetLoops() determines how many times an animation repeats.

The general structure is:

transform.DOScale(1.5f, 1f)
    .SetLoops(3);

This tells DOTween to:

  1. Scale the object to 1.5.

  2. Repeat that animation.

  3. Complete three loops in total.

The important distinction is that the default loop type is LoopType.Restart.


LoopType.Yoyo

LoopType.Yoyo makes the animation play forward and then backward.

Example:

transform.DOScale(1.5f, 1f)
    .SetLoops(4, LoopType.Yoyo);

Instead of snapping back to its original scale, the object smoothly returns to its starting scale.

Yoyo animation

  1. Loop 1

    Scale 1.0 → 1.5

  2. Loop 2

    Scale 1.5 → 1.0

  3. Loop 3

    Scale 1.0 → 1.5

  4. Loop 4

    Scale 1.5 → 1.0

Finished at scale 1.0

Important: The loop count includes both directions. Four loops means two complete forward-and-back cycles.

This is particularly useful for:

  • Button pulsing.

  • Idle animations.

  • Floating objects.

  • UI notifications.

  • Repeated highlighting effects.


LoopType.Incremental

More advanced

LoopType.Incremental makes the animation continue increasing its target value with every loop.

Unlike Restart and Yoyo, it doesn't return to the original target.

Example:

transform.DOMoveX(2f, 1f)
    .SetLoops(3, LoopType.Incremental);

Assuming the object's initial X position is 0:

Incremental animation

  1. Loop 1: X = 0 → 2

  2. Loop 2: X = 2 → 4

  3. Loop 3: X = 4 → 6

Finished at X = 6

Each loop adds the original change (2 units) to the next destination.

This is useful when you want continuous progression instead of repeating the same movement.


SetDelay()

Now let's look at delays.

SetDelay() determines how long DOTween waits before starting an animation.

The general structure:

transform.DOScale(1.5f, 1f)
    .SetDelay(2f);

What's happening?

  1. Wait 2 seconds.

  2. Begin scaling.

  3. Finish scaling after 1 second.


These two methods are easy to confuse.

They both create waiting periods, but they serve different purposes.

SetDelay()

AppendInterval()

Delays the start of a tween

Adds a pause inside a sequence

Usually used on individual tweens

Used when constructing a Sequence

Can be applied before the tween starts

Can be placed between animations


















8. UI Animations

A RectTransform adds properties specifically designed for UI layout:

  • Anchors

  • Pivot

  • Anchored Position

  • Width and Height

  • Size Delta


What's the difference between Position and Anchored Position?

Property

What it represents

transform.position

World position

transform.localPosition

Position relative to parent

rectTransform.anchoredPosition

UI position relative to its anchors

rectTransform.sizeDelta

Size adjustment relative to its anchors


Method

What it animates

Common use

DOAnchorPos()

Anchored position

Sliding menus

DOAnchorPosX()

Horizontal UI position

Horizontal movement

DOAnchorPosY()

Vertical UI position

Vertical movement

DOSizeDelta()

UI size

Expanding panels

DOScale()

UI scale

Button hover

DOLocalRotate()

Local rotation

UI rotation

DOColor()

UI color

Button color changes

DOFade()

Transparency

Fade transitions

DOFillAmount()

Image fill amount

Health bars

DOValue()

Slider value

Progress bars


Camvas Group

Canvas
 └── MainMenu
      ├── Background
      ├── Title
      ├── PlayButton
      └── SettingsButton

Rather than individually fading every child, you can attach a CanvasGroup to MainMenu.

Then:

CanvasGroup menuGroup = GetComponent<CanvasGroup>();

menuGroup.DOFade(0f, 0.5f);

All the UI graphics under that CanvasGroup gradually become transparent.

CanvasGroup properties

Property

Purpose

alpha

Controls transparency, from 0 to 1

interactable

Controls whether child UI elements can be interacted with

blocksRaycasts

Controls whether the group blocks pointer raycasts

Important: Setting alpha = 0 does not automatically disable UI interaction.

That's why it's common to combine transparency with:

menuGroup.interactable = false;
menuGroup.blocksRaycasts = false;