Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LeanTween - A tweening engine that is up to 5x faster than competing engines!

Discussion in 'Assets and Asset Store' started by dentedpixel, Dec 3, 2012.

  1. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    :)
    Well, not to go too off-topic, let me just tell you this as my closing remarks:
    Sublime Text FTW.
     
  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Ahah I apologize, but I couldn't resist: I had to reply about Visual Studio :D In my humble opinion, I find Sublime Text wonderful (I also wrote a blog some months ago, collecting all the current infos on how to configure it with Unity), but only with lose Unity scripts - plus a lot of other non Unity related stuff. When writing Unity DLLs (even if simply C#), Visual Studio is unbeatable though. That said, I'm on Windows, so it's easy for me to say that :p
     
  3. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I too love Sublime Text, and thanks Daniel for that Blog post, that's what I used awhile back to get up and running with the Unity integration, it was very valuable.

    My only complaint is that I wish it offered more autocompletion. Does anyone know how to modify the list of things that are autocompleted? I would love to add in autocompletion support for LeanTween.
     
  4. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Glad you liked it - and thanks to Jacob Pennock, from whom I practically stole half the contents of that blog post :D
    Alex Hokanson seems to have found a way to improve autocomplete, but it seems to work only on Windows. Or you could try to upload a LeanTween package to PackageControl (though it seems like a pain in the ass - I suppose we're asking too much out of Sublime when looking for serious non-hardcoded autocomplete :p).
     
  5. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Awesome @Izitmee I think this will work really well. True, it is an all hard-coded autocomplete, it would be nice to have a solution that scanned the code and generated the autocomplete itself, but I will take what I can get :)
     
  6. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Just to clarify the autocomplete does work on a Mac, and it seems to work very well.

    I submitted the most important functions to the authors Git hub repo, hopefully he/she will accept it into the master repo...
     
  7. nacs

    nacs

    Joined:
    Jun 5, 2013
    Posts:
    6
    Is there any way to move something in an arc or curve instead of just straight line movement with Leantween?
     
  8. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Nacs, unfortunately there is now way to do that, at the moment. But that is a feature I have just started to work on, so hopefully expect that in an update to LeanTween in the near future...
     
  9. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Is the documentation listed anywhere besides your site (dentedpixel.com)? It's currently down.
     
  10. nacs

    nacs

    Joined:
    Jun 5, 2013
    Posts:
    6
    Ah thanks. I like the minimalist nature of your framework and I'm mostly doing mobile dev so the fact that it performs so much better than iTween is great to see.

    Regarding the curved-path request -- I'm looking for a minimal move from point A to point B with a 30 degree curve type of thing. I don't need any fancy move through a follow a series of bezier curves thing (animation path?) or predefined drawn path thing. I'll be happy to do any beta-testing of the Leantween framework as needed.
     
  11. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Sorry about that @DanielQuick, the site is back up now. I have made a standalone version of the documentation as a zip in the past, let me look into doing this again, I can see this being helpful to people when they don't have an internet connection as well...
     
  12. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Glad you enjoy LeanTween :) Spread the word! ;)

    I will throw up the new version on GitHub once I have something in place. It seems like it will be just as easy to make something for a set of bezier curves as one, so that shouldn't be a problem. The only issue is that, it really works best when you can have a bezier path editor, to visualize the curves... but that will have to come later.
     
  13. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    When do you think will PlayMaker-Support come around?

    Edit:

    And how exactly can I tween/rotate/move a GameObject BY a certain Value (Vector3, Float etc.) and not TO a certain Position/etc.
     
    Last edited: Jun 6, 2013
  14. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I was kind of hoping that somebody in the community with PlayMaker experience would pick up the task of writing custom playmaker actions? Anybody out there up to the task? The Playmaker support people made it seem pretty straightforward to do. I just have no experience with Playmaker so it's a bit too much of an undertaking for me right now. I hope to be able to incorporate Playmaker in one of my projects in the future, and that way I can learn as I work on something, but until then I am still a Playmaker n00b.

    In the spirit of not mucking up the code with extraneous methods I purposely left out move relative to the current position, because this can actually be done with all of the current methods. Here is how:

    var relativeMovement:Vector3 = Vector3(0,1,2);

    LeanTween.move(gameObject, gameObject.transform.position + relativeMovement, 1.0 );

    Viola, pretty simple eh?
     
    Last edited: Jun 7, 2013
  15. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Nacs! Support for moving a long a bezier curve has been added :) . There is no visual editor, but if you look in the ExampleJS scene or ExampleCSharp scene, you can see how points are passed to the move function. Let me know if you find any bugs. I will be posting to the Asset Store soon if no issues are found...

    [ > Download LeanTween from GitHub < ]
     
  16. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    ok, i'm kinda desperate... LeanTween class is not available within my scripts, what am i missing, is there any include i failed?

    EDIT: LeanTweenType shows up just fine, tried both js and cs version and nothing, i'm using the lastest 3.5 version of unity
     
    Last edited: Jun 10, 2013
  17. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Is the LeanTween.js file in the Plugins folder? That is all you should need for it to be available in your scripts...
     
    Last edited: Jun 10, 2013
  18. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Hey,

    I'm using LeanTween and I'm loving it. I have a question.

    Is it possible to add a rigidbody.MovePosition tween function?

    I want to ease in and out a isKinematic Rigidbody.


    Thanks,
     
    Last edited: Jun 11, 2013
  19. nacs

    nacs

    Joined:
    Jun 5, 2013
    Posts:
    6
    Fantastic thanks! I'll test it out today and report back if I find any bugs.
     
  20. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    What's up Crazy Robot, I am glad you are liking LeanTween! That is a good request, I will look into what the best way to do this might be. In the meantime it is pretty easy to fake this behavior. Just create an empty gameobject and have the rigidbody follow this objects position on Update, for example:

    PHP:
    var _follow:GameObject;

    function 
    Start(){
    _follow = new GameObject();

    LeanTween.move(_followVector3(3,1,2), 2.0);
    }

    function 
    Update(){
    rididbody.position _follow.transform.position;
    }
    I hope that helps!
     
  21. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    Hi, I really like to see LeanTween.value work with Vector3 as an alternative to float.
     
  22. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    Hi, I have added Vector3 support, Delegates for onComplete and onUpdate. If you are interested to implement this into the project, just let me know. But I only can provide the C# code.
     
  23. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Lopez, that is a good point. I actually just needed this myself the other day.

    I would love to see the C Sharp code. I think I have a good idea of how to implement this too, I will try and get it in the next release...
     
  24. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    View attachment $LeanTween.cs

    Here is my quick and dirty code. I marked my changes with "Added by Markus Gehlhaar".
     
  25. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks a bunch @lopez1de. I am curious what does the C# code look like to call these delegates that you created? I am kind of sick of the String style passing of functions, that I am doing for C# users, so maybe I could do something similar to this for all the C# callback methods...
     
  26. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    Here it is for Vector3, same for float but using the UpdateValueDelegate instead:

    Code (csharp):
    1.  
    2.     public void moveCamera(Vector2 pPosition){
    3.         LeanTween.value(new LeanTween.UpdateVector3Delegate(updateCamera), OT.view.position, pPosition, .5f, mLeanTweenEaseOutSine);
    4.     }
    5.  
    6.     void updateCamera(Vector3 val)
    7.     {
    8.         OT.view.position = val;
    9.     }
    10.  
    mLeanTweenEaseOutSine (shows nice way to init Hashtable on creation):
    Code (csharp):
    1.  
    2.     public Hashtable mLeanTweenEaseOutSine = new Hashtable()
    3.     {
    4.         {"ease", LeanTweenType.easeOutSine} //, {"anotherOption", object}
    5.     };
    6.  
     
  27. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    I found a problem with my "quick and dirty code". You can't have two (or more) delegates on the same GameObjectt. Only the last applied will be handled. That's because you can only add one "onUpdate" at a time. Maybe we can change the code a bit to allow more than one "onUpdate" object?

    EDIT: The problem must be elsewhere. "onUpdate" is a property of a tween (not gameobject as I assumed), and each tween only needs one "onUpdate".


    EDIT2: Found the problem. I'm reusing my hashtables for better performance. You take this hashtable as parameter and modify it. Now my initial created hashtable is modified also, because it is referenced. If I use the same hashtable for more than one tween it gets broken.
    This describes the problem: http://stackoverflow.com/questions/...is-passed-by-reference-or-by-value-by-default
    I have added the following line to the very beginning of pushNewTween() to prevent this:

    Code (csharp):
    1.  
    2.  optional = new Hashtable(optional);
    3.  
     
    Last edited: Jun 17, 2013
  28. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Oh yes you have to be very careful not reuse the hashtables unless that is the expected behavior you want (sometimes it is fine to reuse them if you want them to contain the same values). I prefer to leave it up to the user to make sure they only reuse hashtables when it is the behavior they want.

    Thank you for your code, after looking into it, I doesn't actually make sense for me to incorporate a type of delegate function, because while this would work well in C# code, but Javascript doesn't support this type of delegate type (it has a much more flexible ability to pass actual functions as callback functions, which C# does not provide). I still want to make sure all the calls are consistent from Javascript to C#, and have a C# version that splinters off from the use of the Javascript version.

    So I am planning on adding this Vector3 value update support, but it will have to be passed in the case of C# as a String. I hope you understand. I just submitted a new version of LeanTween (version 1.01) to the Asset Store, but hopefully I can incorporate in the next release...
     
    Last edited: Jun 17, 2013
  29. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    I have a question,
    does this library adds any value on realistic situations?
    I saw the benchmark, but that's not a realistic case. I mean, you wouldn't create 1500 tweens at once on screen. Usually you have a few, in my case I don' t think i've ever had more than 3 tweens on screen at once.
    Does it really make a difference on those cases to use this, hotween or itween?
     
  30. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi creat327, It does make a difference even if you are animating even a modest amount of objects, particularly if you are targeting a mobile device like the iPad/iPhone (although probably not 3 objects). In most situations it won't make a huge difference over HOTween. Check out this video that shows the speed difference on an iPad:



    Although the speed difference isn't the only thing people like about LeanTween. A lot of people seem to prefer how simple and straightforward it is built out, with clear documentation, at least that is what it seems from feedback I have gotten.
     
    Last edited: Jun 19, 2013
  31. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    It's fast and simple. I was able to expand the source code for my needs very quick and easy. You get the full source code.

    For me it turned out that five tweens with NGUI at the same time, results in some stutters on my Android. No problem with LeanTween. But I can't compare LeanTween with the other tween engines you mentioned. But my advice is, always keep it simple and fast as possible. :)
     
  32. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    @dentelpixel i've seen that video before but it has a huge amount of tweens on that one. I'm talking about something way simpler. I only have 2 or 3, on mobile, on iphone 2, 3, 3gs, ipad 1, ipad 2... it was fast. No stutters. My main game: www.dogfightplay.com has a few itweens on screen at the same time and it runs on older devices perfectly fine eventhough it has network connections and lot going on at screen.

    I'm thinking if leantween would speed it up by a considerable amount, for what i see, it makes no difference to use itween or leantween unless you have dozen of objects on screen, that's why i wanted a fair comparison. We would never put 1000 tweens on screen, even if we use leantween!

    I would like to know this before I begin touching code, because changing my system to use leantween instead of itween would require a considerable efford.
     
  33. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    With only a few tweens happening I doubt it would make much of a difference, however most people have a need to tween more than just a few things, so I wouldn't say yours is a typical scenario. In the video iTween is brought to it's knees at only 250 tweens, which could very much be a scenario one could encounter while developing a game. These are just worst-case scenarios of course, but there may be significant but not as noticeable effects at lower values.

    I would suggest downloading the source code for the comparison test I made: http://dentedpixel.com/developer-diary/unity3d-animation-engines-compared/ , and you can alter it to be more in-line with the amount of tweens you are doing to see if it makes enough of a difference to be worthwhile.

    However I think you already answered your own question. If it is already performing well on low-end devices, than there is really no point in migrating the code over... So maybe just think about using it for your next project, when you may have a situation where there will be more than a couple of things tweened.

    The game looks very cool by the way! I will have to check it out on my iphone when I have time :)
     
  34. morton fink

    morton fink

    Joined:
    Mar 13, 2013
    Posts:
    86
    have you compared the performance of leantween and gokit?
     
  35. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Only briefly, I couldn't really grasp the syntax of how things were done with GOKit and since it isn't that popular I didn't put that much time into it. From my brief tests it seemed to fall around the performance of HOTween. If anybody wants to extend my test bed, to include GOKit that would be interesting, it can be downloaded here: http://dentedpixel.com/developer-diary/unity3d-animation-engines-compared/
     
  36. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Actually looking back on my results, it seemed to fall in between HOTween and iTween as far as performance goes (so not very good).
     
  37. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hi dentedpixel , i was wondering if this engine could be integrate with animator timeline wich is an awesome free tool but their animation tween are way to slow for mobile, leantween would be a perfect match for this.
    just a thought...
    thanks
     
  38. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    That product does look very cool, sadly I don't really have time to take on such a project right now, but I would be happy to assist anybody who would like to take on the task (maybe the author of the product, or yourself?)
     
  39. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    I have been researching a new tweening engine because I don't like iTween system of AddComponent/Destroy.

    The "problems" of LeanTween are:

    - No speed option? (included in iTween).
    - No Tween chaining/timeline (an option that it's included in hotween or gokit).
    - No ignore time scale option (it's in iTween).
    - Why all methods are public when they shouldn't be? (static update or all easing methods)
    - Why it's not created in C#? The 90% of the assets in the asset store are in C# because it's a more powerful language than UnityScript. For example in "moveLocalX" I have to pass "null" to the last argument because in UnityScript there is no default arguments.

    I hope you can fix that wishes/suggestions.

    Thanks!
     
    Last edited: Jul 2, 2013
  40. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Will have to give this a try. Main interest at this point is to use this for boid flocking. Possible? Any hints on where to start? I have a script I created some years ago but it is woefully slow and resource intensive.
     
  41. WPCJack

    WPCJack

    Joined:
    Mar 15, 2013
    Posts:
    26
    Hey good asset and I've been enjoying using it.

    Just one question. I noticed that the C# version passes and checks against strings. Have you compared the performance of the Unityscript / C# versions? My understanding was that strings are pretty performance heavy so I just wanted to check.

    Also just a whinge but the C# version throws a few "The private field is assigned but its value is never used" warnings.
     
  42. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey BigKahuna, I am glad you are giving LeanTween a try. It looks like the boid flocking algorithms require you to calculate position of you versus all the other AI objects on every frame, so because of this I don't think LeanTween will be of much help since it is mostly helpful for animating things over many frames...

    It looks like distance has to be calculated a lot for this algorithm, maybe consider using sqrMagnitude to help with performance, magnitude by itself can be seriously resource intensive...
     
  43. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi WPCJack, I am glad you are enjoying LeanTween! If at all possible can you use the LeanTween.js version? The C# version isn't really kept up to date or highly optimized (it was ported over by a very helpful community member, but not by myself)

    In 99% of the cases you should be able to use the Unityscript version of LeanTween with your C# code. It is only provided for people who compile all their code to DLLs using Visual Studio (in this case you cannot use the Unityscript version).
     
  44. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey N3uR0, Thanks for all your feedback. I tried to explain a lot of my design decisions below, but you made some good points I will try to keep in mind when putting out new releases for LeanTween.

     
  45. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Thanks for the reply. Yup, already using sqrMagnitude, just brainstorming for some other possible solutions.
     
  46. WPCJack

    WPCJack

    Joined:
    Mar 15, 2013
    Posts:
    26
    Ok I'm changing across the JS version but I am having a problem with compile errors for value tweening.

    An example of the offending code - which was fine in C#
    LeanTween.value(menuFad.gameObject, "SetAlpha", 1, 0, .25f);

    The error messages
    "Assets/Scripts/BookManager.cs(371,27): error CS1502: The best overloaded method match for `LeanTween.value(UnityEngine.GameObject, Boo.Lang.ICallable, float, float, float)' has some invalid arguments"

    "Assets/Scripts/BookManager.cs(371,27): error CS1503: Argument `#2' cannot convert `string' expression to type `Boo.Lang.ICallable' "
     
  47. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Great, I think you will have much more success with the JS version. I see you have discovered an error in my code, I didn't provide a value function for Strings that doesn't have an optional parameter. If you want to pass an extra parameter like this:

    PHP:
    LeanTween.value(menuFad.gameObject"SetAlpha"10.25fnull);
    It should work, I have also made an update to the engine on Github, if you just want to grab the latest on there.
     
  48. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    BigKahuna, have you checked out this script: http://wiki.unity3d.com/index.php?title=Flocking it seems like a good place to start...

    I can see some speed improvements that could be made to the script, for one they should place the value rigidbody.velocity into a temporary variable instead of accessing it the long way every time. I have been told when you access a value under one of the transform or rigidbody variables it has to use GetComponent to retrieve that value, which can be super slow...

    Edit:
    It looks like the transform using GetComponent was an old problem that has been taken care of, now Unity caches that value, according to sensei Eric5h5:

    http://forum.unity3d.com/threads/96908-Unity-should-internally-cache-transform-for-a-valid-speed-boost

    It does look like there is a ton of other places caching could help with saving GetComponent values though (in the flocking script)
     
    Last edited: Jul 10, 2013
  49. WPCJack

    WPCJack

    Joined:
    Mar 15, 2013
    Posts:
    26
    Hey again,

    Thanks for that, the git version fixed the compile errors though I now get a new runtime error on move. Once again was fine from the C# version.

    NullReferenceException: Object reference not set to an instance of an object
    LeanTween.update () (at Assets/Plugins/LeanTween.js:845)
    LeanTween.Update () (at Assets/Plugins/LeanTween.js:490)

    Cheers,
     
  50. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi WPCJack, I am glad we are getting somewhere. I am not getting errors on any of my C# test scripts. Could you send me the format of the LeanTween call that then creates this error? I think it may have to do with not passing a valid ease function, so double check how you are passing that...