Search Unity

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. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I fixed up the code, to support Flash export again :)

    The latest is on Github: https://github.com/dentedpixel/LeanTween

    I will also submit the update to the Asset Store (probably available in a week).
     
  2. sparrow

    sparrow

    Joined:
    May 6, 2012
    Posts:
    17
    Hey, good job on the LeanTween plugin. I have one suggestion:

    estimated time has been giving me some uncorrect results. So I have modified the LeanTween to use Time.realtimeSinceStartup to calculate the time scale independent delta time:

    Line 534:
    dtEstimated = Time.realtimeSinceStartup - previousRealTime;
    previousRealTime = Time.realtimeSinceStartup;

    This change has been giving me satisfactory results.
     
  3. Ghisallo

    Ghisallo

    Joined:
    Sep 27, 2012
    Posts:
    10
    Thank you very much! Works again in v4.
     
  4. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Nice! Thanks Sparrow, that does seem to get better results than the method I was using. File that under "Why didn't think of that first" ;)

    I think I will use your method from here on, as long as it stands up to testing.
     
  5. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi. I recently started to look for alternatives for iTween, which I have been using in my pet project. I am targetting mobile, so iTween is really not the optimal solution. I was going to utilize HoTween, which claims to be faster than iTween, but then I found this thread and found out that LeanTween claims to be even faster. Plus LeanTween has very similar syntax than iTween does.

    So I gave it a try and it truly is alot faster than iTween! =) I have a puzzle game where I have a lot of tweening when switching a levels that are made of cubes. With Itween on mobile there was clearly visible hickup when making like 200 objects to move at once. That hickup is almost gone with LeanTween. So I definitely recommend LeanTween over iTween, which seems discontinued anyway.

    However, I was not able to completely replace iTween because LeanTween does not have all the handy features that iTween does. Here are the things in iTween that are missing from LeanTween:

    -RotateAdd (demand for this has been already mentioned in this thread. I was able to get around it using onUpdate and use Transform.Rotate there)
    -MoveUpdate (I'm using this to make the camera follow the player in cool lazy way)
    -OnStart (an "event" that fires when the tweening starts, so after the possible delay period)
    -PutOnPath (so you could give 0...1 value and it would put the object on the defined path based on it)

    Also I think the parameter passing to to OnComplete could be a bit more handy. Now you have to create a new hastable even when you have only one param to pass. Im a bit paranoid about using new keyword only when I absolutely must, as it reserves memory from heap, and therefore requires a garbage collection. Maybe also copy the param passing syntax from iTween, its pretty handy there? Making your syntax even more iTween-like would lower the bar to switch tweening engine even more =)

    I read trough the thread and noticed you (Dented pixel) are using UnityScript as your primary language. I heavily suggest you make C# your primary language, UnityScipt is not a real programming language anyway. Theres a reason why pretty much all the "serious stuff" is written in C#. Believe me, you will thank me later if you switch to C#.

    Thank you very much for this awesome free utility, Dented pixel!

    PS: Your documentation is pretty OK, but could be a lot better. For example the onCompleteParam is not really explained there at all. And those game ads on the left..they are a bit disturbing. That monkey face is probably going to haunt me in my dreams as it does when I scroll down =P
     
    Last edited: Nov 12, 2013
  6. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Assault, I have tried to answer your questions and concerns below...

     
  7. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi,

    Thanks for the quick reply. I understood that rotateAround rotates around a given axis. How can that achieve the similar result than RotateAdd, which AFAIK just adds a certain vector3 to transfrom.rotate on each update..? Anyway, I will try the techniques you suggested to achieve the behavior I had with iTween.

    About the curve thing, good to know theres this .point method. But I am unsure how to create the LTBezierPath. With iTween's PutOnPath, I just gave it an array of Vector3:s, and it calculated a curve that runs trough all of the given points. How do I covert that kind of path info in to LTBezier path?

    So for the sake of simlicity, I have 3 known points in space, (0,0,0), (2.5, 5, 0) and (5, 0, 0) which I want the curve to run trough. How can I get the bezier points and handles for similar curve?
    $curve.png
     
  8. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    I know my question about the bezier points and handles is a bit offtopic, but could someone plese explain how can I construct an LTBezierPath that represents the above curve? I'm not sure what are the "the paths should be passed in multiples of 4" part exaclty means in the documentation.
     
  9. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Assault,

    You can get the desired curve by using the following points:

    $diagram.png

    You can also use the LeanTween Editor which makes creating curves very easy.
     
  10. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Cool thanks. One more thing: whats the equation for the handle points? I know only know the start and end point of the curve and I need to calculate the curve at runtime.
     
  11. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Oh, it's all just estimated... I just go a little beyond in the y direction, and then a little to either side for the controls.

    It sounds like you could really use the move through points feature, that iTween and other engines have. I have also been meaning to add this easier to use method (although less precise than bezier). So if you want to just use one of the other engines for the time being and then you should be able to swap in my implementation soon...
     
  12. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Yes, I definitely think it would be good to have a feature similar to iTween's PutOnPath. Would be really handy to be able to just supply some points in space and the method would calculate the curve through them. I wanna ditch iTween completely because of its bad performance and the fact that its not updated anymore.

    Btw, this might come in handy when developing the feature:
    http://www.mvps.org/directx/articles/catmull/
     
  13. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Indeed, I could see it being handy. Thanks for the link! There is also a Unity implementation out there (it was posted on this thread awhile ago), so it shouldn't be too hard to integrate into the engine, I just have to set aside a couple of hours to get it done.
     
  14. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    Hi,

    I asked that before, but I think it was never addressed: the first LeanTween.delayedCall within the scope of Start() is never executed (further DelayedCalls ARE executed then, though!). I work around this by using Invoke with a delay instead, so it's not a real showstopper, but it "feels wrong" looking at the coding then…

    Regards, habitoti
     
  15. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Habitoti,

    I am not sure if I am understanding you right. Are you saying that when a delayed call is implemented in the Start() method it never gets invoked? That would definitely not be good...

    You don't have an example project or code that shows this do you? Also is this in the CS or JS version? Thanks!
     
  16. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    Yes, that's exactly what I am saying. It's in c# (also using LeanTwean.cs). I am traveling right now, so I can't provide a sample, but it's very easy to reproduce. Just put a LeanTween.DelayedCall(1f, test) into the Start() routine, and declare a corresponding void test() {Debug.Log("Yeah");} above it. At least for me, that would never be called. Replacing it by Invoke(test, 1f), however, would work then.

    After that first failing delayedCall, further ones within Start() scope would work, though. I suspected a script order issue first, but I think this fact rather does not speak for that.

    Regards, habitoti
     
  17. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Ok that makes sense Habitoti. I found the problem in the code, and fixed it. You can find the fixed version on Github: https://github.com/dentedpixel/LeanTween

    And I will also update the Asset Store version.

    Thanks for pointing this out.
     
  18. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    Excellent!
     
  19. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hey Dentedpixel. I suppose you have not yet added the PutOnPath thing we talked about earlier? Im asking because I cannot get the desired result using the bezier curves. I think the problem is the placement of the bezier handles, I just cannot calculate them correct.

    It should be possible to calculate a bezier curve based on points in space I want the bezier curve to run trough, right?
     
  20. Pharaoh35

    Pharaoh35

    Joined:
    Dec 25, 2012
    Posts:
    57
    Hi everybody! Now I am trying to use LeanTween and I have a question. When I try

    Code (csharp):
    1. LeanTween.resume(gameObject)
    I have an exception

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. LeanTween.resume (UnityEngine.GameObject gameObject) (at Assets/Plugins/LeanTween.cs:1297)
    Because gameObject at this moment have not got a leantween task. How can I check if gameObject have leantween to choose run resume method or not? Thank you!
     
  21. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    I believe this is related to my posting here…the handle parameters are twisted. To not be incompatible with previous versions, dentedpixel just wants to document this, but I believe everyone will stumble upon this. My recommendation would be to introduce a new correct function with a new name and let the old one silently fade out over time...
     
  22. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    I Good to know that the bezier handles are flipped in the implementation. However, that wasnt the cause why my Im not satisified with the curve I am calculating..

    But I think I found a bug. It seems that LeanTween does not always do the tween I request it to do, and this seems to be random.

    What I am doing is I am making my my main menu items (3DTexts like "Start game", "options", "exit") one by one from outside of the screen to the middle of the screen. Sometimes when I run the game, only the first menu item is brought into the screen, the other ones stay outside of the screen in their initial position as if they did never got moved by the moveLocalX(). I did check that the execution always reaches the pushNewTween() in LeanTween, and that the gameobject is not null. So that makes me thinkg the problem cannot be in my code, but in LeanTween.

    I emphasize that this happens randomly only sometimes when I run the game.

    Heres the code I use to toggle the title screen menu: http://pastebin.com/XyKa5P5T

    So somehow its just silently ignoring the tween..?
     
  23. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    Mabye it's somehow related (at least root-cause wise) to my issue posted here, and the new version with a fix on Github solves yours, too…give it a try.
     
  24. Pharaoh35

    Pharaoh35

    Joined:
    Dec 25, 2012
    Posts:
    57
    Very inconstante lib, do what she wants and when she wants. Sometimes can run callback functions at the start of scripts. I understand, it is free, but using it in your games is impossiblе!!!
     
  25. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    I don't agree, for me it works (using cs-lib). There are still some glitches, but if you properly report them, dentedpixel addresses them.
     
  26. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Habitoti, I got the last version fron github, but the problem persisted. I still dont always get my title screen menu items tweened into the view when I start my game.

    Dentedpixel, to add to my problem descriptipn, Im calling the toggleMenu() that makes the menu items appear in Start(). I can provide more code if needed.
     
  27. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Assault, I am just doing some re-working of the code this weekend, and then I plan to add the catmull path after I do that. So it's second on my list of things to do.

    Unfortunately how bezier curves work it's not so easy to make sure a path runs through a certain point (unless it's one of the end points that you place at that point).
     
  28. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Pharaoh,
    You can check if a gameObject is being tweened or not by using the call: LeanTween.isTweening( gameObject );
     
  29. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Ok good to know you´re working on the catmull path thing, dentedpixel =)

    Btw, you didnt comment on my bug report about tweens sometimes getting silently ignored. Did you already fix it in your weekend code rework? Right now its a big problem in my game, as the menu items stay off screen --> user cannot start the game =/
     
  30. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Assault, I looked through your code a couple of times, and I couldn't see anything wrong...

    I have not had any trouble with tweens being ignored in any of my projects, so I wanted to see if there was maybe something wrong with your code that was at issue, but from just looking at it blindly (without a project implementation) I can't see anything.

    Let me know if you are able to pinpoint the issue...
     
  31. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Well, I noticed that in a situation where the menu items do not appear the isTweening variable is true. So even LeanTween seems to think its doing what it is supposed to. I put my project in a .zip if you wanna take a look. I'll sent you a link in a private msg.
     
  32. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hey..I was reading through this page about different types of Arrays in Unity. On the very bottom it is said that "Hashtable should be avoided, especially if you want to publish to the Windows store, since those collection types are obsolete and have been removed from the version of .NET that's used for Windows store apps."

    So I guess this means I cannot use LeanTween, that uses hashtables internally, in games that are targetting Windows Store..?

    Dentedpixel, do you have any plans to get rid of the hashtable -style parameter passing? Maybe there could be typesafe way to set tween params.
     
  33. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Assault, you can pass all the optional parameters as an array as well, like new object[]{"ease",LeanTweenType.easeOutbounce,"delay",0.5f}

    I am working on a way to pass parameters in a type-safe way (no hashtables or arrays), which should be faster as well. Hopefully I will get that release done this week!
     
  34. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141

    But what about the whole Leantween implementation? it is internally full of Hashtable usages...what happens with the runtime when compiled for Windows phone? I believe Assault is right and using LeanTween might be a showstopper for going for Windows apps...or has anyone a different experience here?
     
  35. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yeah, that is true Habitoti.

    I have been trying to secure a windows 8 computer so I can test out the Windows publishing.

    The new implementation will avoid external use of Hashtables, but I still leave in the Hashtables internally so as to provided backwards compatibility...

    There may be a way to use compilation flags to avoid all the hashtable points for Windows 8, I am not sure, I wouldn't want to splinter off another LeanTween version, or not provided backwards compatibility...
     
  36. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    I think there is not much choice. I understand you need to be backward compatible, but w/o Windows phone support people will rather decide against LeanTween, because why exclude a potential target platform if it's just a click away with Unity otherwise? If I were you, I would throw out hashtables internally per se, and just keep the existing Hashtable signatures for legacy usage for non-Windows platforms (#ifndef UNITY_WINDOWS, I guess). These would just be small wrappers converting to valid APIs then.

    Regards, habitoti
     
  37. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yeah I think you are right, I would really like to support Windows 8 just because there is such a need for it. Hopefully I can just get away with using #ifndef UNITY_WINDOWS so I can still keep backward compatibility...

    Does anyone know of a way I can just try compiling the CS file with .NET on a Macintosh computer? I would rather not have to spend $100 and install Windows 8, as I have no other use for it...
     
  38. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi. Im glad to hear you're working on type safe parameter passing, which is even faster =)

    By the way, just to let you know, I am targeting Windows Phone 8 and the current implementation (that uses hastables) does work. But I havent tried deploying to Windows Store (Windows 8 and Windows RT). Anyway, if you want to try Win 8, install it on virtual machine. Im using Oracle Virtualbox, works great. Let me know if you need any assistance with it.

    Also I dont really get why you could not get rid of hashtables internally? Isn't the backwards compatibility just the matter of the API, meaning the function signatures of Leantween.move() etc? Internally you could use built in arrays or whatever.
     
  39. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Phew! That is good to hear, my head was swimming thinking about how I was going to solve that issue. I think as long as it builds fine you should be fine, submitting to the store...

    Yeah, I am mostly doing away with all of the hashtable stuff (except for backwards compatibility). The main thread of the tweening engine passes optional things using a hashtable, but this will be avoided with the new implementation (but still offering backwards compatibility).
     
  40. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    So if I understood correctly, by backwards compatibility you mean you will still have a version of move() available that accepts a hastable as input parameter, but internally you will convert it to array[]? In other words, when using your new type safe parameter passing, there are no hashtables involved?
     
  41. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yeah, that's basically it. Except I am not converting it to an array, I am converting it to a specific type that is saved on an object. It looks like this:

    LeanTween.moveX( ltLogo, 7.0f, 1.0f, LeanTween.options().setEase(LeanTweenType.punch) );

    But it's not quite finished and tested yet, so I will explain in detail once it is!
     
  42. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Ok, cool! Just keep in mind that in many cases one wants to set multiple parameters than just the ease type, like delay and OnComplete function and so on.
    I hope you also refactor the way the oncompleteparams are passed while you are at it =)
     
  43. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hey dentedpixel :) Just as a heads-up, since I had similar problems to fix with HOTween (though concerning advanced reflection instead than hashtables): quite absurdly, Windows Phone 8 has a way wider compatibility range than regular Windows Store. In short, Windows Phone 8 has similar limitations to Android, while Windows Store 8 has similar limitations to iOS builds with stripping level set to max :p
     
  44. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Definitely, that is taken into account, two parameters would be set like this:

    PHP:
    LeanTween.moveXltLogo7.0f1.0fLeanTween.options().setEase(LeanTweenType.punch).setDelay(0.5f) );
    And you can continue to daisy chain them until you are satisfied.
     
  45. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Daniele! Oh man, good to know, so I guess Windows phone 8 != Windows Store

    Hey Assault, or anyone else targeting Windows let me know if there are errors on the Windows Store targeting... I know, I know I need to plunk down the $100 and get myself on the windows bandwagon.
     
  46. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Ahah no need to get on the terrible Windows 8 bandwagon: you're better without (I don't have it either: am still on Windows 7) :D I'm sure users will help you :)

    P.S. and yes, definitely, Windows Store != Windows Phone 8 (in absurd ways)
     
  47. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Well, Windows Store != Windows Phone 8 because they are separate operating systems. But I don't blame you, Microsoft is very skilled in confusing the consumers with having unnecessarily multiple versions of this and that. Good think the latest news is they realize the confusion and are going to different direction..

    So far I have only built my game for Windows Phone 8 and that works fine with the current version of LeanTween. But I just installed Windows 8 SDK (which is separate to Windows Phone 8 SDK) and tried building my game for Windows Store. Leantween.cs (+ all my scripts that use hashtable) give the following error:

    Assets\LeanTween\Plugins\LeanTween.cs(165,9): error CS0246: The type or namespace name 'Hashtable' could not be found (are you missing a using directive or an assembly reference?)

    So it seems the hastable and therefore LeanTween truly is unusable in games targetting Windows Store..
     
  48. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Ok thanks Assault, it looks like I will maybe have to get busy with the #ifdef or split off a clean LeanTween 2.0 without any hashtables... I am leaning towards the #ifdef, as I don't really want to segment the code...
     
  49. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Assault!

    I have put up a preview of LeanTween 2.0 on Github: github.com/dentedpixel/LeanTween

    Would you mind downloading it and seeing if it works for Windows Store? Or anybody else out there on Windows 8? I have put in conditionals for whether or not it is being compiled against .NET wherever hashtables are used (only in 5 places now). So hopefully that will make it Windows Store compatible...

    I am pretty excited about the new type-safe clean way of passing optional parameters, I have implemented too. I think it should both speed things up, and make it much better for C# coders out there.

    parameters will now be passed like:
    PHP:
    LeanTween.moveXgameObject0.0f0.5f ).setEase(LeanTweenType.easeInQuad).setDelay(0.5f);
    This will also mark a turning point in LeanTween where I am migrating to a C# only code-base (JS users will still be 100% supported though).
     
  50. Hambag

    Hambag

    Joined:
    Apr 23, 2013
    Posts:
    4
    After moving the "plugins" folder to the root folder (the one containing the "assets" folder): console errors
    After moving the contents of the "plugins" folder outside into the root folder: console errors

    I'm pretty sure I know where the root folder is. These are both types of errors I'm getting:

    The name `LeanTween' does not exist in the current context
    The name 'LTRect' does not denote a valid type ('not found').