| Type | Third-party library (free) |
|---|---|
| Namespace | DG.Tweening |
| Author | Demigiant |
| Get it | Unity Asset Store: "DOTween (HOTween v2)" |
| Paid version | DOTween 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.
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
- Add "DOTween (HOTween v2)" from the Asset Store to your assets, then import it via Window > Package Manager > My Assets.
- 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.
- Add
using DG.Tweening;to your scripts.
Shortcuts: Transform
Called directly on components. All return a Tweener.
| Method | Description |
|---|---|
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
| Target | Methods |
|---|---|
Material | DOColor(Color, duration), DOFade(float alpha, duration) |
SpriteRenderer | DOColor, DOFade |
CanvasGroup | DOFade: fades a whole UI panel and its children |
Image (UI) | DOColor, DOFade, DOFillAmount(float, duration) |
RectTransform | DOAnchorPos(Vector2, duration): move UI elements |
Camera | DOShakePosition, DOFieldOfView, DOOrthoSize |
AudioSource | DOFade(float volume, duration), DOPitch |
Rigidbody | DOMove, 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);
| Method | Description |
|---|---|
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
| Method | Called |
|---|---|
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
| Method | Description |
|---|---|
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().
| Method | Description |
|---|---|
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
- 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. - DOTween has one hidden manager object that updates all active tweens each frame (after
Updateby default), setting the value based on elapsed time and the ease curve. - When the tween finishes,
OnCompleteruns and the tween is killed (recycled) by default. A killed tween can't be restarted; create a new one or useSetAutoKill(false). - 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
SetLinkor callDOKill()inOnDestroy.
Common Mistakes
- Starting a new tween on the same property every frame (in
Update). Tweens pile up and fight. Start tweens on events (click, hit, pickup), not every frame. - Two tweens fighting. Spamming a button starts a new scale tween while the last one runs. Call
transform.DOKill()first, orComplete()the previous one. - Menu animations don't play while paused. Add
.SetUpdate(true). DOFadedoesn't exist on Image. The UI module wasn't enabled. Open the DOTween Utility Panel and run Setup again.- Tweening a Rigidbody's Transform. Physics and the tween fight. Use the Rigidbody shortcuts or make it kinematic.
See also
- Tutorial: Game Feel with DOTween
- Coroutines (the manual alternative)
This page is a simplified, AI-assisted interpretation. For the complete and authoritative reference, see the official DOTween documentation.