Upgrade guide: from HOTween to DOTween

Posted by on Apr 6, 2015 in Tech Stuff | No Comments

HOTween to DOTween

This upgrade guide is aimed at HOTween users that want to switch to the new (and much much better, if I may say so—and by Jove I can: I made them both) DOTween.

The logic

HOTween and DOTween share the same logic. They both have Tweener, Sequence, and more generic Tween classes. They both have the same range of settings for easing, loops, callbacks etc (though DOTween has additional ones). They both use the same kill/autoKill behaviour.

The API logic

Basic tween creation

With HOTween, you had to create a TweenParms object, then use strings to assign the property to tween. Settings like ease/loops/etc were chained to the TweenParms object, instead than to the tween itself. DOTween scraps TweenParms to take a more direct approach. Also, settings are now chained to the tween itself (more on that later).

For example, let’s see the differences when creating a tween that moves a transform’s position to 3,4,5 in 2 seconds.

HOTween Logo MIN

DOTween Logo MIN

As you can see, no more strings. The generic way is slightly longer than HOTween, but is completely type-safe, and the shortcuts way is very short and functional. Both HOTween and DOTween return a Tweener, which you can also store as a generic Tween.

Tween settings

As mentioned before, in DOTween you just chain settings directly to the tween instead than to TweenParms (which also introduces nicer code formatting, a very good thing for nerds like us). All settings start with Set, so they’re easy to find when IntelliSense is at work.

For example, this is the same tween as before, but with an added OutBounce ease and two Yoyo loops.

HOTween Logo MIN

DOTween Logo MIN

Another important difference, is that you can’t tween more than one property with the same Tweener, as you could with HOTween (by chaining multiple Props to the same TweenParms). But DOTween is so much more efficient that it’s not a big deal at all.

Callbacks

Callbacks are very similar once again. They all start with an On (OnComplete, OnStepComplete, OnStart, etc). Here is a couple examples, to show how to use both a parameter-less callback and one with parameters.

FROM tweens

In HOTween, you created FROM tweens by using HOTween.From instead than HOTween.To. In DOTween, it’s just another chained setting. But it comes with one requirement: it must be chained immediately after the tween creation.

For example, this is the same tween as before, but with a FROM behaviour.

HOTween Logo MIN

DOTween Logo MIN

Sequences

Sequences work practically the same way (and share the same stupid name). You still have the same Append/Insert/Prepend methods (and you also have a new Join one) for both tweens and callbacks. Plus, callbacks now work even within nested Sequences. Not to mention you can have completely empty Sequences made only of callbacks.

Default settings and Init

You can set default static settings via code, as in HOTween. But there’s actually a better way. Just set them using DOTween’s Utility Panel (accessible from Unity’s Tools menu), and let them be loaded when calling DOTween.Init() (or the first time you launch a tween).

DOTween Utility Panel

TweenParms: are they really gone?

Actually no. There is a TweenParams (note the additional A) class in DOTween too. But it’s there only as a utility, to allow you to store common parameters to be applied to multiple tweens. After you store your settings into a TweenParams object, you assign them using SetAs. Note that SetAs can also take another tween as a parameter, so you can directly apply the settings of an existing tween to another.

For example, let’s say that we want to create two different tweens with the same ease and loop settings…

Final considerations

You now know all you need to switch to DOTween. Don’t forget to check out the docs, and to discover all the new features you have at your disposal (like DOVirtual.DelayedCall, or changing a tween’s value while tweening, or blendable tweens, or coroutines, or blahblahblah).

Bye, I’m outta here. Gotta feed sparrows!

Leave a Reply