DOTween
TypeThird-party library (free)
NamespaceDG.Tweening
AuthorDemigiant
Get itUnity Asset Store: "DOTween (HOTween v2)"
Paid versionDOTween Pro

DOTween

DOTween is a popular free library for tweening: smoothly changing a value from A to B over time. Move a door, fade a menu, pop a coin, shake the camera, each in one line of code instead of a hand-written coroutine.

Not made by UnityDOTween is a third-party asset by Demigiant, not part of Unity. This page covers the free version. Its official documentation is at dotween.demigiant.com.

You're a film director. Without DOTween you're animating frame by frame, redrawing the door a little more open every frame. With DOTween you tell an assistant: "Open this door to 90 degrees, take one second, ease out at the end, and tell me when you're done." The assistant does all the in-between frames (the tweens) for you.

Setup

  1. Add "DOTween (HOTween v2)" from the Asset Store to your assets, then import it via Window > Package Manager > My Assets.
  2. When the setup window appears (or via Tools > Demigiant > DOTween Utility Panel), click Setup DOTween... and Apply. This turns on the modules for UI, Physics, Audio and so on.
  3. Add using DG.Tweening; to your scripts.

Shortcuts: Transform

Called directly on components. All return a Tweener.

MethodDescription
DOMove(Vector3 to, float duration)Move to a world position. Also DOMoveX/Y/Z for one axis.
DOLocalMove(Vector3 to, float duration)Move to a local position.
DORotate(Vector3 to, float duration, RotateMode mode = Fast)Rotate to euler angles. Use RotateMode.FastBeyond360 to spin more than 360.
DOLocalRotate(...)Same, in local space.
DOScale(Vector3 or float to, float duration)Scale. Pass a float for uniform scale.
DOLookAt(Vector3 towards, float duration)Turn to face a point.
DOJump(Vector3 to, float jumpPower, int numJumps, float duration)Hop to a position. Returns a Sequence.
DOPunchScale(Vector3 punch, float duration, int vibrato = 10, float elasticity = 1)Quick bounce that returns to the start. Also DOPunchPosition, DOPunchRotation.
DOShakePosition(float duration, float strength = 1)Random shake, returns to the start. Also DOShakeRotation, DOShakeScale.

Shortcuts: other components

TargetMethods
MaterialDOColor(Color, duration), DOFade(float alpha, duration)
SpriteRendererDOColor, DOFade
CanvasGroupDOFade: fades a whole UI panel and its children
Image (UI)DOColor, DOFade, DOFillAmount(float, duration)
RectTransformDOAnchorPos(Vector2, duration): move UI elements
CameraDOShakePosition, DOFieldOfView, DOOrthoSize
AudioSourceDOFade(float volume, duration), DOPitch
RigidbodyDOMove, DORotate: moves via the physics engine

TextMeshPro shortcuts and the visual DOTweenAnimation component are part of DOTween Pro (paid).

Tweening anything: DOTween.To

For values without a shortcut, give DOTween a getter and a setter:

private float score;

// Count the displayed score up from its current value to 1000 over 1 second.
DOTween.To(() => score, x => score = x, 1000f, 1f)
       .OnUpdate(() => scoreText.text = Mathf.RoundToInt(score).ToString());

Settings (chain after any tween)

Settings return the tween, so you can chain them: transform.DOMoveY(3f, 1f).SetEase(Ease.OutBounce).SetDelay(0.5f);

MethodDescription
SetEase(Ease ease)The "feel" of the motion. Ease.Linear, OutQuad (default-like), OutBack (overshoots a bit), OutBounce, InOutSine...
SetLoops(int loops, LoopType type)Repeat. -1 = forever. LoopType.Yoyo goes back and forth; Restart jumps back; Incremental keeps adding.
SetDelay(float seconds)Wait before starting.
SetRelative()Treat the target as an offset: DOMoveY(2f, 1f).SetRelative() moves up by 2.
From()Go from the given value to the current one. Great for "appear" animations.
SetUpdate(true)Ignore Time.timeScale. Needed for pause menus.
SetLink(GameObject go)Kill the tween automatically when go is destroyed. Strongly recommended.
SetAutoKill(false)Keep the tween after it finishes so you can replay it.
SetId(object id)Tag it, so you can control it later with DOTween.Kill(id).

Callbacks

MethodCalled
OnStart(callback)When it starts (after any delay).
OnUpdate(callback)Every frame while it runs.
OnStepComplete(callback)Each time a loop finishes.
OnComplete(callback)When it's completely done.
OnKill(callback)When it's killed, whether it finished or not.

Controlling tweens

MethodDescription
tween.Kill(bool complete = false)Stop and delete it. With true, jump to the end first.
tween.Pause() / Play()Pause and resume.
tween.Restart()Start over (needs SetAutoKill(false) if it already finished).
tween.Complete()Jump to the end.
tween.PlayBackwards() / PlayForward()Reverse it. Handy for open/close panels.
tween.IsActive() / IsPlaying()Check its state.
transform.DOKill()Kill all tweens on that target. Also works on other components.
DOTween.KillAll()Kill every tween.
yield return tween.WaitForCompletion();Wait for it inside a coroutine.

Sequences: chaining tweens

A Sequence is a timeline of tweens. Create one with DOTween.Sequence().

MethodDescription
Append(tween)Add at the end: plays after the previous one.
Join(tween)Play at the same time as the previously appended tween.
Insert(float atTime, tween)Place at an exact time in the timeline.
AppendInterval(float seconds)Add a pause.
AppendCallback(callback)Run code at that point.
Prepend(tween)Add at the start.
Sequence s = DOTween.Sequence();
s.Append(chest.DOScale(1.2f, 0.2f))                  // 1. grow
 .Join(chest.DOShakeRotation(0.2f, 15f))             //    while shaking
 .Append(chest.DOScale(1f, 0.1f))                    // 2. back to normal
 .AppendCallback(() => lid.gameObject.SetActive(false))
 .Append(coin.DOMoveY(2f, 0.5f).SetRelative().SetEase(Ease.OutBack)) // 3. coin pops out
 .SetLink(chest.gameObject);

What happens at runtime

  1. Calling DOMove (or any shortcut) creates the tween and starts it automatically, on the next frame. Settings you chain on the same line are applied before it starts.
  2. DOTween has one hidden manager object that updates all active tweens each frame (after Update by default), setting the value based on elapsed time and the ease curve.
  3. When the tween finishes, OnComplete runs and the tween is killed (recycled) by default. A killed tween can't be restarted; create a new one or use SetAutoKill(false).
  4. If the target is destroyed while the tween runs, DOTween's safe mode usually catches it and stops the tween, but it's cleaner to use SetLink or call DOKill() in OnDestroy.

Common Mistakes

See also