LeanTween 2.0 – Faster, Type-safe and C#

LeanTween 2.0 – Faster, Type-safe and C#

Dec 12

LeanTween 2.0 does away with passing optional parameters via Hashtables or Arrays, and instead turns to a more robust and cleaner way of passing these parameters with functions. All optional parameters are now passed at the end of the tweening method like so:

LeanTween.moveX( go, 1f, 2f).setEase(LeanTweenType.easeInQuad). setDelay(1f).setOnComplete( someMethod );

You can “daisy-chain” as many optional parameters you want to the end of a method (or none at all).

Some benefits of this new method are more consistent code between using it with Javascript or C#. It’s type-safe! There is no longer any confusing about what the name of a variable is and what type to make it. It’s also faster with less overhead involved. Best of all it now supports Windows Phone 8 and Windows Store publishing (Windows Store publishing only supports the new way of passing optional values, not the old hashtable method).

If you want to go about using the old Hashtable or Array method of passing optional parameters LeanTween will still be backwards compatible.

LeanTween 2.0 is now only offered with a C# file but don’t worry javascript is still very much supported. All of the methods are available in Javascript, and what’s great is that calling the methods look nearly identical in both languages. LeanTween 1.1 can still be downloaded for legacy projects that you do not wish to update.

Performance Differences
I ran some tests, to see how much faster the new 2.0 was vs 1.18 using the new performance analyzer with FPS Graph. Below are the results, but to summarize it was about 4% faster. Not too much faster, but every bit counts! Also the new format is much cleaner for passing parameters (you may notice how many lines of code and cruft this helps you avoid).

What I was most impressed with was how the frame-rate drops encountered during my stress-tests were much smaller than the drops in 1.18 (which is a good thing). This is illustrated in the graph below that gives the lowest fps encountered over the 5 stress tests.

Notes on Upgrading
the id of the tween is no longer returned by the tweening method. instead to retrieve this you need to call .id at the end of the method ex:

int uniqueTweenId = LeanTween.scaleZ(gameObject, 1f, 1f).id;

Then you can send this to the cancel/pause/resume methods like before:

LeanTween.pause( uniqueTweenId );


  1. This is great, I was just up all last night using Leantween in my game. Then this morning I was confused with the online documentation that changed. But this version makes much more sense, I think Leantween has now surpassed anything else for use-ability. Good work !

    I hope the unity asset store will be updated soon.

  2. One Sly Fox

    Sweet! When’s this going to be available in the Asset Store?

    I just got a Surface RT recently and tested my game on it. It seems to have some compatibility problems, but LeanTween seemed to compile alright.

    How wasn’t 1.1 compatible with WP8 and WS?

    Awesome work!

  3. Sorry for the confusion, but I am glad you are excited. I am submitting it the Asset Store tomorrow, so it should make it up by early next week. Until then, you can get v2.0 on Github http://github.com/dentedpixel/LeanTween (very little will probably change compared to the Asset Store version).

    1.1 was only not compatible with Windows Store (the phone seemed to work). Windows Store compiltes against .NET which does not support any hashtables, so it was a win-win getting rid of them in the new implementation :)

  4. John

    Hi Russell,

    I’ve just found your great sounding Tween engine and I’m trying to port from iTween at the moment. I’m having trouble with passing parameters to my onComplete function:

    LeanTween.move (prefab, new Vector3(x, y, 0), 0.2f) .setOnCompleteParam(gameObjectToPass) .setOnComplete(ReOrderAnimComplete) .setOnCompleteTarget(gameObject);

    ReOrderAnimComplete takes a GameObject parameter.

    It’s throwing an error saying parameters do not match delegate System.Action() paramters… any idea what’s wrong?

    Many thanks

    • Hi John,
      I suspect that your ReOrderAnimComplete may be in the wrong format. It should look like this if you want to pass an onComplete param:

      ReOrderAnimComplete( object hash ){
      Hashtable h = hash as Hashtable; // type the object as whatever it was originally
      Debug.Log(“onComplete finished hash:”+h["yo"]);

      For a working example, check out the ExampleCSharp.cs that is included (rotateExample).

      Also, there is no need to set the onCompleteTarget, I actually have taken that out in the latest version to avoid any confusion….

      I hope that helps, feel free to reach out on the Unity forums, as that is the easiest place to dialogue and share code examples :)

  5. Oscar

    how about blackberry 10? is it supported

    • It looks to work, at least it builds without any errors. I do not have any test devices to confirm it, but I would be surprised if it builds and then doesn’t work.

      Do people actually use Blackberry? I figured people had given up bothering developing for that system…

  6. I am new to Unity and this library is just what I need to move everything around like I did in cocos2d. While trying to see if there were CCJumpBy/To methods or a way to implement them, I noticed the example for SetLoopPingPong() is incorrect.

    That’s it. Thanks for all the work you do on this!

    • Nice! Cocos2d is pretty great as well, I have used that in the past (before I discovered Unity).

      Thanks for the tip, I will update the documentation.

  7. Dream_Catcher

    Is this a mistake?
    beziers[k] = new LTBezier(pts[i+0],pts[i+2],pts[i+1],pts[i+3],0.05f);

    and this one is right? beziers[k] = new LTBezier(pts[i+0],pts[i+1],pts[i+2],pts[i+3],0.05f);

    • Hi Dream_Catcher, unfortunately that was intended. The “control” for the bezier point is not the one next to it on the list, but rather one away. I flipped these values by mistake while writing the code, and I cannot flip-them back to what would logically make sense because that would probably mess up everyone’s projects :(

      I will attempt to make this more clear in the documentation, but a fool-proof way to use the bezier curves is to use the LeanTween editor…

      • Dream_Catcher

        Hi Russell, thanks for replying. I am already fixed this for my intentions.

        It is a really great stuff. Thank you a lot!!!

  8. EpiKnightz

    Sometime I encounter a rare problem: the LeanTween GameObject that created in the scene (aka the “~LeanTween”) still stay there even after stopped play-testing. Adding these code will help solve the problem, and it make the Hierarchy look cleaner too:

    public void Awake ()
    gameObject.hideFlags = HideFlags.HideAndDontSave;

    I don’t know if put it in Awake() would be a good idea though, as I don’t have deep understanding about your code. Pls tell me if I’m wrong.

    • That’s a good idea EpiKnightz. I have never encountered this bug myself, but I have heard of others having it, so I guess it’s best to put in there for those rare scenarios.

      • EpiKnightz

        Forgot to tell you guys, if anyone else having the same problem and try the solution above, remember to add these codes too or else it will create memory leak problem sometimes

        public void OnApplicationQuit ()
        DestroyImmediate (this.gameObject);

  9. Vladislav

    I like using LeanTween in my projects, it’s convinient and simple but
    my team and I encountered some problems in LeanTween.
    1) if you use method setOnComplete is causes a memory leak.
    OnComplete is never set to null or cleared. Which saves a link for an object and doesn’t let Unity to unload this object from memory
    Changing this lines to:
    this.onComplete = null;
    solves the problem.

    2)Using method reset(); causes appearing of multiple ~LeanTween object in hierarchy. We have 2 scenes in the game: Lobby and Ingame. We use LeanTween only in Ingame. If calling reset(); before moving from Ingame to Lobby causes a ~LeanTween object to appear. As much times we change scenes from Ingame to Lobby as many ~LeanTween objects in hierarchy we had.

    • Hi Vlad,
      Thank you for letting me know about these bugs. I wasn’t aware of either of them. I have fixes for both of the issues up on github: http://github.com/dentedpixel/LeanTween . You may want to try not calling reset at all to see if it works, it will have better performance, LeanTween is built to be called once and then never again, but reset shouldn’t hurt performance too much either if you want to keep it that way.



  1. Using Unity Toolkit 2D and LeanTween | The Rombos-Blog - [...] It has so much more great features that Unity does not offer (or only for Pro). For tweening, I ...

Leave a Reply