Blog

iTween for Unity

iTween is an animation library I created which focuses on the premise of “minimum input for maximum output” to make your life easier when it comes to shaking, spinning, moving, fading, coloring, controlling audio, fading cameras, and just about everything else you can think of in Unity.

At it’s core, iTween is an interpolation system that takes one value and animates it to another over a given amount of time. Where iTween shines is in its action-specific syntax that frees you from a production or coding mind-set and places you in more of an action-movie director position. At the end of the day iTween allows you to command, point, and lovingly coerce, while speeding up nearly every facet of your development process without sacrificing production value.

But I can already do these things by…

Now, before we dig into the “how-to’s” of iTween let’s answer the “why” behind it’s existence. As the saying goes, “there’s more than one way to skin a cat” and getting things to come alive in Unity is no exception to that rule. You can animate in external 3D applications or with Unity’s built in animation timeline; You can utilize JavaScript, C# or Boo and tackle things through pure, monotonous code; You can realize that you sit somewhere in the middle of these talent spectrums and ponder if you can afford the cost of someone who knows what you don’t. Now don’t get me wrong, before I show you proof of it’s abilities, I want to make it known that iTween is NO slouch when it comes to creating powerful results; simplicity does not equal simple in this case. In fact it’s been battle-tested by big and small game studios, follows the solid foundations of tweening libraries in the Adobe Flash world, and my son thinks it’s cooler than sliced bread. The bottom line is iTween is efficient, fast, simple and fits into nearly every project for use in simply adding pizazz all the way up to powering fundamental game mechanics and systems.

Ok, I’m still here. Where do I start?

iTween is available for download from http://itween.pixelplacement.com. iTween is a single C# file that can be used with ANY of the programming languages that Unity supports, as well as all versions of Unity. If you plan on using JavaScript or Boo you will need to create a “Plugins” folder (if you don’t already have one) in your “Assets” folder for iTween to live in. If you plan on using C# you can place it anywhere you want within your “Assets” folder. That’s it for installation; I told you “minimum input for maximum output”.

Hello World!

Before we get into actually using iTween there’s a few basic things I want to point out:

  • Nearly all of iTween’s methods have 2 “flavors”: a “simple” version and a “customizable” version.
  • The “customizable” versions of iTween methods use Hashtables for their property setting.
  • Nearly every iTween method needs a reference to a GameObject.
  • iTween can be used in Update functions for repeated calls but there are specific methods included, which are geared towards this and offer significant performance benefits.

iTween can do tons of things but let’s start with something simple; moving from one position to another. The tool for this challenge is iTween’s MoveTo() method. Lets animate a GameObject from it’s current position to (2,0,0) over 2 seconds using the “simple” version of MoveTo():

iTween.MoveTo(gameObject, Vector3(2,0,0), 3);

Simple, and easy, but what if we wanted some more control over this animation? We would need to use the “customizable” version of MoveTo() and provide it’s properties with a Hashtable:

iTween.MoveTo(gameObject, {“x”:2, “time”:3, “loopType”:”pingPong”, “delay”:1));

This call to MoveTo() will still animate the GameObject’s position on the “x” axis to a value of 2 over a span of 3 seconds but it will also delay this animation for 1 second and ping-pong the motion back and forth.

To unlock the real power of iTween you will want to dig into the “customizable” versions of each method and all of their parameters (for a complete list please consult the documentation page at http://itween.pixelplacement.com/documentation.php).

Hashtables are ugly.

There’s a plethora of parameters for you to tweak and play with. In fact, MoveTo() is capable of taking a series of points in space that can be used as a smooth path to follow with the “path” parameter. The only problem is that with great power comes REAL ugly, but its an ugly you can live with.

Where “ugly” really rears its head is with using iTween from C#:

Hashtable parameters = new Hashtable();
parameters.Add("x",2);
parameters.Add("time",3);
parameters.Add("looptype",iTween.LoopType.pingPong);
parameters.Add("delay",1);
iTween.MoveTo(gameObject, parameters);

If you are keeping count that’s 6 times the amount of work it took the JavaScript example from earlier to do the exact same thing. That’s hardly in keeping with “minimum input for maximum output”! But never fear, iTween has a solution to make C# just as concise as the JavaScript version; say “hello” to Hash(). With iTween’s Hash() method we can shorten that C# script down to:

iTween.MoveTo(gameObject, iTween.Hash(“x”,2,“time”,3,“loopType”,”pingPong”,“delay”,1));

Much better! Notice Hash() takes alternating values of a parameter followed by a value.

All this for the enormous price of free.

iTween is backed by a regularly updated support site that contains numerous examples, full documentation and information for receiving support and reporting bugs. The only cost to you for iTween is the grand total of absolutely nothing. That’s right, I worked tirelessly on iTween for roughly 5 months while taking care of my pregnant wife, working my day job as the Interactive Creative Director at Bully! Entertainment (http://bullyentertainment.com), spending time with my 9-year-old son, playing with our 2 dogs, shunning our 2 cats, completing many home improvement projects and completely avoiding sleep. My goal behind this endeavor was to help the community, get my name circulated and to learn C#. I’m where I am in my career as a result of many nameless individuals who have answered questions and offered help over the past 15 years and I want to pay this forward in the hopes of helping others.

iTween isn’t the solution for every problem you’ll face but I hope it works well for everything you need it for. My hope is that my hard work will help many, including myself, put out creative and quality projects with “minimum input for maximum output”. Good luck with everything you attempt.

16 Comments

  1. Ovidiu
    November 17, 2010

    Hello and a very big thank you from Romania 🙂 Awesome library ( just starting with unity ) !
    Please keep up the great work!

    Have Fun!

  2. November 24, 2010

    First off I wanted to say thanks for all your hard work on iTween – it’s awesome!

    Thought I’d point out the there’s an error in this line which also appears your Unity Creative article. Notice the curly bracket instead of a parentheses after “delay”,1

    iTween.MoveTo(gameObject, iTween.Hash(“x”,2,“time”,3,“loopType”,”pingPong”,“delay”,1});

    • November 24, 2010

      Thanks for pointing that out! Corrected.

  3. Tom
    November 24, 2010

    Hi

    http://itween.pixelplacement.com/examples.php

    Are the example’s code free to reuse in games too (not copyrighted)?

    • November 24, 2010

      Yes sir, learn and build from them.

  4. Devon
    January 25, 2011

    Hey, i added a plugins folder and put itween in it, but im still getting the “unknown identifier” message from my console… any suggestions?

    • January 26, 2011

      Can you provide the actual error? Have you checked the forums?

  5. Helios
    January 26, 2011

    When I try using MoveTo with UnityScript, i get an error “MoveTo is not a member of iTween. Did you mean moveAdd?”. I could have sworn this used to work before when i tried out iTween. Am I missing something? Thanks!

    • January 26, 2011

      “moveAdd” was part of iTween 1.0. All methods in iTween are now initial case so that would be “MoveAdd”. Please upgrade your iTween version.

    • Helios
      January 27, 2011

      Ack, I had an older version of it buried in the project that was conflicting with the new one. Thanks.

  6. Mustafa
    March 11, 2011

    Hello… Love what I see… I am very new to Unity and even iTween for that matter. But iTween makes so many things so easy!

    I have a question… And I have no idea how it all works… Is it possible?

    I make 2 paths(path_1, path_2) which are parallel to each other… Player follows path one… The moment player presses a button… it follows path_2 from the same point of the level… I am trying hard to figure it out.. I am even planning to buy one of the examples.. but confused which one will really suite my needs!

    Thanks a lot,
    Mustafa

  7. Flo
    March 15, 2011

    This work of yours is AWESOME!
    I am donating some money to you RIGHT NOW and I will keep donating for every new update released!

    I just found this library and I think it’s BRILLIANT work !

    Thank you!

    • March 15, 2011

      Thanks so much for the support and I’m glad iTween is helpful!

  8. increpare
    April 16, 2011

    This makes my life more pleasant. Thanks.

    <3

  9. loya
    December 21, 2011

    hi!
    First of all, thank you for your great work.
    I’ve seen there used to be a javascript version but I can’t find now.
    Is it still existing? where can I find it please?
    Thanks.

    • January 5, 2012

      You can still get the JS version from the Google code repository but I would not recommend it as it is very outdated at this point. Please read the “Getting Started” page of the iTween support site because you can use JS with the C# version of iTween. Just place it in a folder called “Plugins” and you are good to go.