LeanTween Speed Comparison to iTween

LeanTween Speed Comparison to iTween

Nov 30

For tweening operations LeanTween is over 5x faster than iTween in my tests! In the included example you can see LeanTween animating 1,500 boxes Running at 1.86ms frame intervals versus iTween’s 9.94ms. 5x faster speed is great, but the huge advantage is that there are no sudden drops in framerate. Unlike iTween where in my example you can see it drop down to 1.53 frames per second (or 652ms to render a frame), and this is on a Mac Pro desktop machine! On mobile it would be much worse (comparison with iTween on mobile).

LeanTween’s low overhead and excellent speed is achieved by it’s smart reuse of objects, which avoids garbage collection and the associated frame drops. There are also many gains by having a single For Loop that executes code in a very optimized manner.

You can download my example project if you want to test out the differences for yourself, or compare the difference below:

LeanTween – Animating 1,5000 boxes

iTween – Animating 1,5000 boxes

The speed difference is shown in my other project FPS Graph:

I was prompted to write this post, not because I hate iTween, it’s a very well thought out package, but I am in shock that iTween is the most downloaded tweening library for Unity. Particularly with most developers using Unity with an eye on mobile development it seems a waste to hand so many precious CPU cycles over to something as simple as tweening.

19 comments

  1. Sajid

    I’m curious as to why you felt the need to create a tweening library in the first place. Did you notice a speed-drop in a particular game of yours, or was it because you needed a feature that iTweens didnt provide?

    Nevertheless, interesting library, and will check it out as soon as some documentation is provided. Thanks for making it free. 🙂

  2. Hi Sajid,
    Yes when I first starting developing my game Monkeyshines the only tweening engine out there was iTween, which I did notice frame hiccups with (when I was only doing a few tweens at a time). I actually have written a tweening engine in the past for the web (javascript), so I figured I could create my own that would do things more efficiently. Viola LeanTween!

    Thanks for checking it out, There are examples provided in the Plugins folder (with the download from the Asset Store), but I also plan on writing some documentation for it too.

  3. a

    Is there any way to just drop in and replace itween without any code changes?

  4. For the HOTween performance comparison are you reusing Tweeners, or are the params set to Autokill? http://www.holoville.com/hotween/tips.html

  5. Hi Thom, well the tweens are all unique (going to different position end points), so simply re-running the tween wouldn’t produce the same behavior. You can download the sample project though, and tweak it yourself to see if you can garner better performance. Also I want to point out that there are no tricks, or hoops you have to go through to get these extra performance boosts with LeanTween. It simply works faster straight out of the gate…

    Anonymous, it is not meant to be a clone of iTween. It is structured differently, in a way that I think is more clean and obvious to use, but that I suppose is debatable. I will have documentation up in the next couple of days, but until then you can look at the source code that I think makes things pretty clear.

  6. Max

    Great tweening engine. I’ve just transferred from iTween to LeanTween and everything works perfectly.

  7. Madgeniy

    I’m very glad to use LeanTween. Please, add feature like oncompletetarget in iTween, it would be great. Thanks.

    • Hi Madgeniy, I am glad you are enjoying LeanTween, That is a very good idea! It won’t be as handy for people using Javascript, but a couple of people have complained there is no way to distinguish where the onComplete commands are called in C#. This seems like an excellent solution to this problem. I will look into including this in the next update of Leantween (probably in the next week or two).

    • I needed that as well, here’s a patch that implements it:

      http://www.linuxized.com/files/patches/leantween.oncompletetarget.patch

      Thanks for LeanTween, solid work 🙂

      • Thanks so much Alex, it’s been so great to see other people in the community helping to write updates! I have submitted a version of LeanTween that uses similar code to yours to the Asset Store today (it also supports onUpdateTarget).

        Thanks everyone for their input, if you can’t wait for it to be approved in the Asset Store, you can get it here: https://code.google.com/p/leantween/downloads/list

        • You’re welcome 🙂

          Leantween has been a lifesaver for my current project (my first unity game :)), found it after experiencing the dreaded iTween spikes with multiple concurrent tweens. Your work is awesome!

          Just the other day I made another addition to leantween: ALPHA_VERTEX support. I’ll send the patch your way soon.

          Please consider moving your project to github to make merge requests easier 🙂

  8. Yaniv

    Would be great if someone was so kind to port it to Playmaker and make custom actions for it !

    • I totally agree Yaniv, unfortunately I don’t have time to do so myself right now but I would be happy to assist anyone else who wishes to port it to Playmaker.

  9. vihang

    hi there,

    first of all good job! i really love this plugin! anyways i have some newbie questions! I have been able to move an object along the set path but i want it to run only once! also i used the oncompletefunc and wanted to stop the movement but there is no stop method? only way i could stop is to destroy the path array!

    Secondly i have a dynamic path so the vector array is not multiple of fours! so it keeps throwing errors….

    • Russell

      Hi Vihang! Thanks a bunch, I am glad you are liking it 🙂 . Just a note for the future it is best to post questions on the forums (forum.unity3d.com/threads/leantween-a-tweening-engine-that-is-up-to-5x-faster-than-competing-engines.161113/unread), as I notice it faster and more people can help answer your question(s).

      It shouldn’t run more than once unless specified, just make sure there is no setLoop or setRepeat being applied. Or do a setRepeat(1). You can also save a reference to the tween and do savedId.cancel() or LeanTween.cancel( gameObjectThatIsTweening ), to cancel things already under way.

      Bezier paths have to be a multiple of four for them to work correctly, so it is really important to pay attention to those complaints ;). You are probably better off using the catmull spline implementation. Check out the PathSplines example to see that in action, it’s a little more straightforward to implement than the bezier variety…

  10. Tobias

    Hey! Great plugin!
    Is there a way to add custom parameters to delayedCall?

    • Yes you can do that like:

      void Start(){
      object tweenFinishedObj = “hi” as object;
      LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished, tweenFinishedObj );
      }

      void tweenFinished( object obj ){
      string returnObj = obj as string;
      }

Trackbacks/Pingbacks

  1. Les news de ZJP. Février 2013. 1/2 | Unity 3D – France - [...] - LeanTween est un nouveau moteur de tween apparemment beaucoup plus performant qu’iTween surtout si beaucoup d’objets sont impactés…
  2. Graphical enhancements | Apps @ Burlock.org - [...] stuttering in the tween animations on my tablet and it’s possible that iTween is the culprit, if Lean Tween’s…

Leave a Reply