Master DoTween for unity Animations.
If you’re a game developer or animator, you may be familiar with DotTween. DotTween is a powerful and flexible tweening engine for Unity, designed to help you create smooth and fluid animations with ease. In this blog, we’ll explore what DotTween is, how it works, and why it’s such a valuable tool for game development.
What is DotTween?

DotTween is a tweening engine for Unity, which allows you to create animations and transitions between different states easily. Tweening means creating intermediate frames between two keyframes, allowing for smooth and fluid animation. DotTween provides a wide range of easing functions, allowing you to easily create animations that start slow, speed up, or gradually slow down towards the end.
DotTween was created by Demigiant, a team of Unity developers, and is available as a free asset on the Unity Asset Store. It’s an open-source project, meaning you can view and modify the source code.
How does DotTween work?
DotTween is designed to be simple and easy to use, with a small API that’s easy to understand. To use DotTween, you must add the DotTween component to an object in your scene. This component allows you to specify the target object and the properties you want to animate. You can then use the various methods provided by the DotTween API to create animations.
One of the most powerful features of DotTween is its support for multiple target objects. You can create animations that affect multiple objects simultaneously, allowing you to create complex animations easily. For example, you could create an animation that moves several objects at once or changes the color of multiple objects.
DotTween also provides a wide range of easing functions, allowing you to easily create animations that start slow, speed up, or gradually slow down toward the end. These easing functions can create various effects, such as bouncing, elastic, or back-and-forth animations.
Why is DotTween useful for game development?
DotTween is a valuable tool for game development for several reasons:
- Easy to use: DotTween is designed to be simple and easy to use, with a small API that’s easy to understand. This makes it a great tool for beginners just starting with game development.
- Powerful: Despite its simplicity, DotTween is a powerful tool that can easily create complex animations. Its support for multiple target objects and a wide range of easing functions make it a flexible tool that can be used to create a wide range of effects.
- Efficient: DotTween is designed to be efficient and optimized for performance. This means that it can create smooth and fluid animations without impacting the performance of your game.
- Open-source: DotTween is an open-source project, meaning you can view and modify the source code. This allows you to customize the engine to suit your specific needs.
- Free: DotTween is a free asset on the Unity Asset Store. This makes it an accessible tool for developers who may not have the budget for more expensive tweening engines.
Examples of how to use DotTween

Let’s look at a few examples to give you an idea of how DotTween can be used.
- Move an object from one position to another.
One of the simplest things you can do with DotTween is to move an object from one position to another. To do this, you must add the DotTween component to the object you want to animate. Then, you can use the DOMove method to specify the target position and the duration of the animation:
transform.DOMove(new Vector3(10, 0, 0), 1f);
This will animate the object’s transform position to move from its current position to a position of (10, 0, 0) throughout 1 second.
- Scale an object
You can also use DotTween to scale an object. To do this, you can use the DOScale method, which allows you to specify the target scale and the duration of the animation:
transform.DOScale(new Vector3(2, 2, 2), 1f);
This will animate the object’s transform scale to increase from its current scale to a scale of (2, 2, 2) throughout 1 second.
- Rotate an object
You can also use DotTween to rotate an object. To do this, you can use the DORotate method, which allows you to specify the target rotation and the duration of the animation:
transform.DORotate(new Vector3(0, 0, 90), 1f);
This will animate the object’s transform rotation from its current rotation to a rotation of (0, 0, 90) throughout 1 second.
- Change the color of an object.
You can also use DotTween to change the color of an object. To do this, you can use the DOColor method, which allows you to specify the target color and the duration of the animation:
GetComponent<Renderer>().material.DOColor(Color.blue, 1f);
This will animate the object’s material color to change from its current color to blue for 1 second.
- Chain animations
One of the most powerful features of DotTween is its ability to chain animations together. This allows you to create complex animations involving multiple objects and stages. To chain animations, you can use the Sequence method, which allows you to create a sequence of animations:
Sequence = DOTween.Sequence();
sequence.Append(transform.DOMove(new Vector3(10, 0, 0), 1f));
Sequence.Append(transform.DOScale(new Vector3(2, 2, 2), 1f));
sequence.Append(transform.DORotate(new Vector3(0, 0, 90), 1f));
This will create a sequence of animations that move the object to a position of (10, 0, 0), then scale the object to (2, 2, 2), and finally rotate the object by 90 degrees around the z-axis.
Conclusion
DotTween is a powerful and flexible tweening engine for Unity that allows you to create smooth and fluid animations easily. Its simple API, support for multiple target objects, and wide range of easing functions make it a valuable tool for game development. DotTween is efficient, optimized for performance, and available as a free asset on the Unity Asset Store. If you’re a game developer or animator looking to create complex animations with ease, DotTween is worth checking out.
Sure, here are some additional points about DotTween:
- Easing functions
DotTween supports a wide range of easing functions that allow you to customize the way your animations behave. Easing functions control the rate of change of a value over time and can be used to create animations that feel more natural and intuitive. DotTween supports easing functions such as Linear, InOutQuad, InOutCubic, InOutQuart, InOutQuint, and many more. You can also create your own custom easing functions by implementing the IEase interface.
transform.DOMoveX(10f, 1f).NetEase(Ease.OutBounce);
This will animate the object’s transform position to move from its current position to a position of (10, 0, 0) using an OutBounce easing function, which creates a bouncing effect at the end of the animation.
- Path animations
DotTween also allows you to create path animations, which involve moving an object along a predefined path. To create a path animation, you can use the DOPath method, which allows you to specify a list of points that define the path as well as the duration of the animation:
Vector3[] path = { new Vector3(0, 0, 0), new Vector3(5, 0, 5), new Vector3(10, 0, 0) };
transform.DOPath(path, 1f, PathType.CatmullRom);
This will animate the object’s transform position to move along a path defined by the three points (0, 0, 0), (5, 0, 5), and (10, 0, 0) over a duration of 1 second, using a CatmullRom path type.
- Tween callbacks
DotTween allows you to specify callbacks that get executed at various points during the animation. This allows you to perform additional actions or trigger events based on the state of the animation. To specify a callback, you can use the OnComplete, OnStart, and OnUpdate methods, which allow you to specify a delegate method to be called:
transform.DOMoveX(10f, 1f).oncomplete(() => Debug.Log(“Animation complete!”));
This will animate the object’s transform position to move from its current position to a position of (10, 0, 0) over a duration of 1 second and then call the specified delegate method when the animation is complete.
- Tween control
DotTween provides a number of methods that allow you to control the behavior of an ongoing tween. For example, you can pause, resume, or stop a tween using the Pause, Play, and Kill methods:
Tween = transform.DOMoveX(10f, 1f);
tween.Pause(); // Pause the tween
tween.Play(); // Resume the tween
tween.Kill(); // Stop the tween
This allows you to create more dynamic and interactive animations that respond to user input or other events in your game.
- Performance
DotTween is designed for high performance and efficiency and is optimized for use in real-time applications such as games. DotTween uses a custom timing system that is designed to minimize the overhead of updating the animation state and uses a pre-allocated pool of tween objects to avoid garbage collection overhead. DotTween also provides options for customizing the update rate and maximum capacity of the tween pool, allowing you to fine-tune the performance of your animations.
Overall, DotTween is a powerful and versatile tool for creating animations in Unity, with a wide range of features and options for customizing the Look and feel of your animations. Whether you’re creating simple, linear animations or complex, path-based animations with custom easing functions and callbacks, DotTween makes it easy to achieve the desired effect.
Furthermore, DotTween is designed to integrate seamlessly with Unity and provides a number of features that make it easy to use and customize within the Unity editor. For example, you can use the built-in Unity timeline system to create and control DotTween animations, and DotTween also provides a custom inspector panel that allows you to see and edit the properties of a tween directly within the editor.
In addition to its core features, DotTween also provides a number of additional extensions and plugins that extend its functionality and make it even more versatile. For example, the DOTween Pro extension adds support for skeletal animations and animation blending, while the DOTween Path plugin provides additional options for creating and editing path-based animations.
In terms of learning resources, DotTween has a comprehensive documentation website that provides detailed information about its features and usage, as well as examples and tutorials to help you get started. There are also a number of third-party resources and tutorials available online, such as YouTube videos and blog posts, that can help you learn how to use DotTween effectively.
Overall, DotTween is a powerful and versatile tool for creating animations in Unity, with a wide range of features and options for customizing the look and feel of your animations. Whether you’re a beginner or an experienced Unity developer, DotTween is an excellent choice for creating high-quality animations that enhance the overall user experience of your game or application.
For details, see https://bleedingedge.studio/blog/
Comments
Post a Comment