Get HOTween

Here it is (.zip)

For release notes, changelog, and HOTween's Visual Editor, head to Download.

Ohno! This column is so empty! What will I do now?

Maybe writing some non-sentences will help...

Like... CATAPRAXIS!

See the camel?

Revolution?

Megarobots are cool, but the conversation is quite boring

Sanity is overrated

Jelena is an awesome comic artist

Yuhuuuu?

History teaches us what went wrong, so that next time we can go wrong more quickly

x + 3 = Mister X

y + 4 = Madame Y

z + 5 = zzzzzz

Don't tell me you're reading this! Seriously?

No, that's not what I said. That's what YOU said

Bonk!

We are going doooown

And dooooowner!

Oh, look, more non-sentences below!

X: "Hey, have you seen my socks?"
Y: "What am I? Your sockretary?"

This will never end

I'm getting hungry. As soon as I finish writing these things I'm eating something big

Exploramation

What happened to Frank Miller?

I have a cat whose name is Blues, but she's not very bluesish

I wonder...

Is that a wall? A typewriter? A pumpkin? Oh no: it's Humbert! Hey, Humbert, you look good today!

A

B

C

I have 23 more of those, but I'll keep them for later...

Catapraxis! Oops, I'm repeating myself

Now this is the punishment for doing such long pages

Is this it?

D

E

Told you I was keeping some for later

Ulysses Rejoyce

Yes, I'm inventing all this stuff in a single session: that's what too much coding will bring you

Chester Brown: I just love his stuff

Did I mention that I was hungry?

Enough!

See ya

No really, I'm stopping now

...

END

DOTween (HOTween v2) IS OUT!
More than 4x faster, more efficient, and with tons of new features.
Check it out

To see HOTween's full API check HOTween API

HOTween.Init

Call this method once when your application starts up, before the creation of your first tween (if you call it after you create your first tween, it will have no effect), to initialize HOTween immediately instead than having it being automatically initialized when the first Tweener/Sequence is created.

HOTween.Init(permanentInstance,renameInstanceToCountTweens,allowOverwriteManager)

OverwriteManager

HOTween's OverwriteManager works in the background, and automatically checks if a running tween needs to be overwritten by a newly started one. It's awesome and you should use it :)

OverwriteManager is deactivated and disabled by default. You have to activate it via HOTween.Init, and enable it via HOTween.EnableOverwriteManager().

Enabling OverwriteManager HOTween.Init(false, false, true); HOTween.EnableOverwriteManager();

You can disable it again by calling: HOTween.DisableOverwriteManager().
Even when disabled, a small part of the OverwriteManager will still run in the background (if it was activated), so that when you enable it it's ready to take control.

Disabling OverwriteManager HOTween.DisableOverwriteManager();

HOTween.To

To animate an object, you need to create a Tweener. This is simply achieved using HOTween.To(...), in one of 3 possible ways:

HOTween.To(target, duration, propName, endValue)

HOTween.To(target, duration, propName, endValue, isRelative)

HOTween.To(target, duration, propName, endValue, isRelative, easeType, delay)

HOTween.To(target, duration, parameters)

HOTween.To will return a Tweener. You can either store it for direct use (or to add it to a Sequence), or you can ignore it and just let it run. Unless you expressly choose otherwise, once an animation is complete the Tweener will be destroyed.

HOTween.From

Works exactly as HOTween.To, but will animate from the given value instead than to.

Note that, unless you start the tween in a paused state, the OnStart callback will be called immediately, even if a delay was set. This happens because the target will immediately jump to the From value.

HOTween.From(target, duration, propName, fromValue)

HOTween.From(target, duration, propName, fromValue, isRelative)

HOTween.From(target, duration, propName, fromValue, isRelative, easeType, delay)

HOTween.From(target, duration, parameters)

HOTween.From will return a Tweener. You can either store it for direct use (or to add it to a Sequence), or you can ignore it and just let it run. Unless you expressly choose otherwise, once an animation is complete the Tweener will be destroyed.

HOTween Static Methods and Properties

Think of HOTween's class as a manager for all the tweens (both Tweeners than Sequences) that you create, which lets you control all existing tweens with various filters:

Controls

Based on the additional parameters you pass to each control method, all control operations can be filtered in different ways. Where you read "first-level", it means that if a Tweener/Sequence is inside another Sequence, it is not taken into account (first-level Sequences control all their nested Tweeners/Sequences, thus there's no need to go deeper):

()
All tweens (both Tweeners than Sequences) will be involved.
(target)
The operation will involve first-level Tweeners whose target is the given one.
(id)
The operation will involve first-level Tweeners/Sequences whose id is the given one.
(intId)
The operation will involve first-level Tweeners/Sequences whose intId is the given one.
(tweener)
The operation will involve the given first-level Tweener.
(sequence)
The operation will involve the given first-level Sequence.

Complete()

Kill()

Pause()

Play()

PlayBackwards()

PlayForward()

Restart()

Reverse()

Rewind()

Other Methods

GetAllTweens()

GetAllPlayingTweens()

GetAllPausedTweens()

GetTweenersByTarget(target, includeNestedTweens)

GetTweensById(intId, includeNestedTweens)

GetTweensByIntId(id, includeNestedTweens)

IsLinkedTo(target)

IsTweening(target/id/intId)

Properties

defEaseType
The default EaseType for new Tweeners/Sequences that don't specify it.
defLoopType
The default LoopType for new Tweeners/Sequences that don't specify it.
defTimeScale
The default time scale for new Tweeners/Sequences that don't specify it.
defUpdateType
The default UpdateType for new Tweeners/Sequences that don't specify it.
showPathGizmos
If true, shows the eventual paths in use by PlugVector3Path.
totTweens
The total number of first-level Tweeners and Sequences, paused or not (first level means that Tweeners or Sequences contained in other Sequences don't count).
warningLevel
The level of debug output in case an error is encountered and resolved without throwing exceptions.

Tweener

Tweeners are the low-level workers, and are directly responsible of the animations of an object. You create one each time you use HOTween.To, and you can store a reference to it to use its methods or properties:

Methods

ApplyCallback()

Complete()

GetPathLength()

GetPointOnPath()

GoTo()

GoToAndPlay()

Kill()

Pause()

Play()

PlayBackwards()

PlayForward()

ResetAndChangeParms()

ResetPath()

Restart()

Reverse()

Rewind()

UsePartialPath()

WaitForCompletion()

WaitForRewind()

Properties (can be changed even while the tween is playing)

autoKillOnComplete
If set to false, doesn't clean nor remove this Tweener from HOTween's list when it is completed.
easeAnimationCurve
Assigns a Unity AnimationCurve to use as easing for this tween, overriding all previously set easings.
easeType
The EaseType used by this tween. Setting it overrides all previously set easings.
enabled
If set to false, this Tweener won't be updated, and any use of animation methods (Play/Pause/Rewind/etc.) will be ignored (both if called directly via the Tweener instance, than if using HOTween.Play/Pause/Rewind/etc.).
id
Eventual ID of this tween (more than one Tweener/Sequence can share the same ID, thus allowing for grouped operations).
intId
Eventual int ID of this tween.
loops
Number of times this tween will run (-1 means infinite loops).
loopType
The LoopType used by this tween.
position
Gets and sets the time position of this tween (loops are included when not infinite, delay is not).
timeScale
Time scale used by this tween.

Read-Only Properties

completedLoops
Number of loops that have been completed.
delay
The delay that was set for this tween.
duration
Duration of this tween, loops and delay excluded.
elapsed
Elapsed time within the current loop (delay excluded). Note that elapsed will be equal to duration only when all the loops are completed, otherwise each time a loop is completed, completedLoops is augmented by 1 and elapsed is reset to 0.
elapsedDelay
Elapsed delay.
fullDuration
Full duration of this tween, loops included (when not infinite) but delay excluded.
fullElapsed
Full elapsed time including loops (but without considering tween delay).
hasStarted
Returns true after this tween was started for the first time.
isComplete
Returns true while this tween is complete.
isEmpty
Returns true if this Tweener has no property to tween (means that no valid property to tween was set).
isLoopingBack
Returns true when this tween is in the "going back" part of a Yoyo/YoyoInverse loop.
isPaused
Returns true if this tween currently paused.
isReversed
Returns true if this tween is set to go backwards (due to a call to Reverse()).
target
The Tweener's target.
updateType
The UpdateType used by this tween.

Tween Parameters (TweenParms)

Tween parameters are represented by a TweenParms object, who is created via method chaining. Method chaining simply consists of a series of functions joined together, like Func1().Func2().Func3().
To create a tween's parms, you start with a new TweenParms(), and then chain the desired methods, which represent different options. Code assist will help you see which parameters are available, and to quickly auto-complete them.

All parameters are specific to the current tween and optional (but you will have to add at least one Prop, otherwise the tween won't know what to animate). For all the parameters that you don't chain, default values will be used.

Example new TweenParms().Prop("fieldName", 2).Ease(EaseType.easeOutQuad).Loops(2).OnComplete(myOnCompleteFunction);

The available parameters are:

Properties parameters

Prop(propName, endValue, isRelative)

Prop(propName, tweenPlugin)

NewProp(propName, endValue, isRelative) / NewProp(propName, tweenPlugin)

Optional parameters

AutoKill(autoKill)

Delay(delay)

Ease(easeType / animationCurve)

Id(idName)

IntId(id)

KeepEnabled/KeepDisabled(behaviour/behaviour[]/gameObject/gameObject[])

Loops(loops, loopType)

Pause()

PixelPerfect()

TimeScale(timeScale)

UpdateType(updateType)

SpeedBased()

Callback parameters

OnComplete(callbackFunction, additionalParameters)

OnComplete(sendMessageTarget, methodName, value)

OnPause(callbackFunction, additionalParameters)

OnPlay(callbackFunction, additionalParameters)

OnPluginOverwritten(callbackFunction, additionalParameters)

OnRewinded(callbackFunction, additionalParameters)

OnStart(callbackFunction, additionalParameters)

OnStepComplete(callbackFunction, additionalParameters)

OnUpdate(callbackFunction, additionalParameters)

Tween Plugins

To access plugins, you have to use/import the Holoville.HOTween.Plugins package in your script.

When you set up a Prop parameter, HOTween auto-detects the default tween plugin to use, based on the type of the property and the end value. However, there are times when you don't want to use a default plugin (like when you want to animate a property in a "different" way). In those cases, instead of simply writing the endVal, you can direcly set the desired plugin, instantiating it as a Prop.

Default number animation VS using a plugin who tweens through integers // Regular Prop: seen that the property and endValue are floats, // HOTween will use a PlugFloat plugin, that will tween the value using floating point numbers. HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",90)); // Direct plugin instantiation: in this case we're using a PlugInt, // which will animate a numeric value only through integers. HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",new PlugInt(90)));

Every plugin has these 3 main parameters (of which only endVal is required):

endValue
The value to tween to.
ease/animationCurve
The EaseType or AnimationCurve to use for easing.
isRelative
If true, the given endValue is considered relative instead than absolute (this means that the animation will tween BY the end value, instead than TO it).

Additionally, some plugins have additional parameters, which are set via method chaining.

Using a regular plugin HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",new PlugInt(90,EaseType.easeInQuad,true)));

Using a plugin with additional chained parameters // PlugVector3Path has various additional method chaining parameters, // among which ClosePath(), which will automatically close the given path smoothly, // to allow cyclic motion. HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",new PlugVector3Path(path,EaseType.easeInQuad,true).ClosePath()));

Default Plugins

Default plugins are set automatically, depending on the type of property (float, Vector3, Quaternion, etc.), thus you will never need to directly set them.

PlugColor(endValue,ease/animationCurve,isRelative)
Animates Color values.
PlugFloat(endValue,ease/animationCurve,isRelative)
Animates numbers.
PlugQuaternion(endValue,ease/animationCurve,isRelative)
Animates Quaternion values (endValue can be either a Quaternion or a Vector3 representing the rotation's euler angles).
PlugRect(endValue,ease/animationCurve,isRelative)
Animates Rect objects.
PlugString(endValue,ease/animationCurve,isRelative)
Animates a string, writing each character overtime. If isRelative is set to true, the endValue will be added to any existing string. Otherwise, existing strings will be overwritten while the new one is composed.
PlugVector2(endValue,ease/animationCurve,isRelative)
Animates Vector2 values.
PlugVector3(endValue,ease/animationCurve,isRelative)
Animates Vector3 values.
PlugVector4(endValue,ease/animationCurve,isRelative)
Animates Vector4 values.

Additional Plugins

I will add more plugins overtime, so check HOTween API to see the full list.

PlugInt(endValue,ease/animationCurve,isRelative)

PlugQuaternion(endValue,ease/animationCurve,isRelative)

PlugSetColor(endValue,ease/animationCurve,isRelative)

PlugVector3Path(path,ease/animationCurve,isRelative,pathType)

PlugVector3X(endValue,ease/animationCurve,isRelative)

PlugVector3Y(endValue,ease/animationCurve,isRelative)

PlugVector3Z(endValue,ease/animationCurve,isRelative)

Sequence

Sequences are used to wrap Tweeners or other Sequences inside a timeline, which can then be controlled as it was a simple tween.

Contrary to Tweeners, Sequences are created in a paused state, and you'll have to call mySequence.Play() to start them.

Delays and loops added to Tweeners won't work correctly inside Sequences. Use AppendInterval to add delays between each Sequence element instead

Creating a new Sequence

Before adding stuff to a Sequence, you have to create it. This is simply done by using the new keyword, and then setting the desired sequence parameters (SequenceParms) with method chaining - exactly as TweenParms worked.

A new sequence with 3 Yoyo loops and an OnComplete callback mySequence = new Sequence(new SequenceParms().Loops(3,LoopType.Yoyo).OnComplete(MyFunction));

Adding tweens, intervals, and other sequences to an existing sequence

Append(tweenComponent)

AppendCallback(parameters...)

AppendInterval(duration)

Insert(atTime,tweenComponent)

InsertCallback(atTime, parameters...)

Prepend(tweenComponent)

PrependInterval

Methods

ApplyCallback()

Clear(parameters)

Complete()

GoTo()

GoToAndPlay()

Kill()

Pause()

Play()

PlayBackwards()

PlayForward()

Restart()

Reverse()

Rewind()

WaitForCompletion()

WaitForRewind()

Properties (can be changed even while the tween is playing)

autoKillOnComplete
If set to false, doesn't clean nor remove this Sequence from HOTween's list when it is completed.
enabled
If set to false, this Sequence won't be updated, and any use of animation methods (Play/Pause/Rewind/etc.) will be ignored (both if called directly via the Sequence instance, than if using HOTween.Play/Pause/Rewind/etc.).
id
Eventual ID of this Sequence (more than one Tweener/Sequence can share the same ID, thus allowing for grouped operations).
intId
Eventual int ID of this Sequence.
loops
Number of times this Sequence will run (-1 means infinite loops).
loopType
The LoopType used by this Sequence.
position
Gets and sets the time position of this Sequence (loops are included when not infinite).
timeScale
Time scale used by this Sequence.

Read-Only Properties

completedLoops
Number of loops that have been completed.
duration
Duration of this Sequence, loops excluded.
elapsed
Elapsed time within the current loop. Note that elapsed will be equal to duration only when all the loops are completed, otherwise each time a loop is completed, completedLoops is augmented by 1 and elapsed is reset to 0.
fullDuration
Full duration of this Sequence, loops included (when not infinite).
fullElapsed
Full elapsed time including loops.
hasStarted
Returns true after this Sequence was started for the first time.
isComplete
Returns true while this Sequence is complete.
isEmpty
Returns true if this Sequence contains no other Tweeners or Sequences.
isLoopingBack
Returns true when this Sequence is in the "going back" part of a Yoyo loop.
isPaused
Returns true if this Sequence is currently paused.
isReversed
Returns true if this Sequence is set to go backwards (due to a call to Reverse()).
updateType
The UpdateType used by this Sequence.

Sequence Parameters (SequenceParms)

Sequence parameters are represented by a SequenceParms object, who is created via method chaining, and works exactly as TweenParms. Method chaining simply consists of a series of functions joined together, like Func1().Func2().Func3().
To create a Sequence's parms, you start with a new SequenceParms(), and then chain the desired methods, which represent different options. Code assist will help you see which parameters are available, and to quickly auto-complete them.

All parameters are specific to the current Sequence and optional. For all the parameters that you don't chain, default values will be used.

Example new SequenceParms().Id("sequence_01").Loops(2).OnComplete(MyOnCompleteFunction);

The available parameters are:

Optional parameters

AutoKill(autoKill)

Id(idName)

IntId(id)

KeepEnabled/KeepDisabled(behaviour/behaviour[]/gameObject/gameObject[])

Loops(loops, loopType)

TimeScale(timeScale)

UpdateType(updateType)

Callback parameters

OnComplete(callbackFunction, additionalParameters)

OnComplete(sendMessageTarget, methodName, value)

OnPause(callbackFunction, additionalParameters)

OnPlay(callbackFunction, additionalParameters)

OnRewinded(callbackFunction, additionalParameters)

OnStart(callbackFunction, additionalParameters)

OnStepComplete(callbackFunction, additionalParameters)

OnUpdate(callbackFunction, additionalParameters)

IHOTweenComponent Interface

IHOTweenComponent is a powerful interface, shared by Tweeners and Sequences. By storing Tweeners/Sequences as IHOTweenComponents, you can seamlessly control them in the same way, without caring if they're a Tweener or a Sequence.

To see all the methods and properties available for IHOTweenComponent, check HOTween API.

TweenVar

TweenVar is a special object you can create to setup a "virtual" tween, which will not be automatically tweened nor updated, but will just set and return a value when you call myTweenVar.Update(elapsed, isRelative).

To see its details, check HOTween API.

Example: creating and storing a TweenVar TweenVar myTV = new TweenVar(10,20,1); Debug.Log(myTV.Update(0.5f)); // logs: 15

Example: getting an immediate value without storing a TweenVar Debug.Log(new TweenVar(10,20,1).Update(0.5f)); // logs: 15

Methods

Update(elapsedTime, isRelative)

Properties

duration
Virtual duration (you could also set it to 1 or 100 to treat is as a percentage).
startVal
Start value (you can consider it as a FROM).
endVal
End value (you can consider it as a TO).
easeType
The EaseType to use for time calculations.

Read-Only Properties

value
The current value of this TweenVar (set when you create the TweenVar, and changed each time you call Update).
elapsed
The current elapsed time (changed each time you call Update).

HOTween Visual Editor

HOTween's Visual Editor comes in two almost identical forms: a global editor where you can add tweens for any element on the scene, or a Component that you can add to a GameObject (HOTweenComponent - not related to the IHOTweenComponent interface - which works great with prefabs too).

The global visual editor is accessed via Window > HOTween Visual Editor in Unity's menu.

The HOTweenComponent editor is added to a GameObject by selecting it, and going to Component > HOTween > HOTweenComponent in Unity's menu.

Being a visual editor, there is no scripting involved, though you can access all the tweens created by a HOTweenComponent via myHOTweenComponentInstance.generatedTweens (you must have the "destroy component" button disabled to do this - see picture below).

Example: accessing all the Tweeners created by a HOTweenComponent HOTweenComponent tweenComponent = myGameObject.GetComponent<HOTweenComponent>(); if (tweenComponent != null) { List<Tweener> tweeners = tweenComponent.generatedTweeners; // Do something with the Tweeners }