Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    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. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    211
    Quick question:
    Anyone noticed issue with LeanTween.rotateAround and LeanTween.rotateAroundLocal, where it snaps target UI element to (0,0) on the ui canvas (element doesnt retain its original position)?

    LeanTween.rotate and LeanTween.rotateLocal works OK (doesnt invalidate elements position), but is not what i need.

    If nobody knows what im talking about i might make example project once i get teh time. let me know pls. thanks!
     
  2. dentedpixel

    dentedpixel

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

    Not sure why you are getting an error there, do you have the latest LeanTween? I put together this test that works fine:

    Code (CSharp):
    1. Vector3[] splineArr = new Vector3[] {new Vector3(-1f,0f,0f), new Vector3(0f,0f,0f), new Vector3(4f,0f,0f), new Vector3(20f,0f,0f), new Vector3(30f,0f,0f)};
    2. LTSpline cr = new LTSpline( splineArr );
    3.  
    4. Debug.Log("Point 2:"+cr.ratioAtPoint(splineArr[2]));
     
  3. Schromercy

    Schromercy

    Joined:
    Oct 26, 2013
    Posts:
    4
    Hello dentedpixel,

    I am using iTween before and found performance issue, then i found your plugins. It works great. But i cannot find some feature that i can found in iTween, such as:
    1. How to move gameobject using speed, not using time? I need to do this to move every object with the same speed
    2. iTween has shakeScale function to shake the scale for some quite time, do leantween support this too?
    Thank you
     
  4. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Schromercy,
    I am glad you are liking it so far :). LeanTween actually didn't have a speed option, but that feature has been requested many times in the past so I just implemented it this morning, you can get the latest on github (look under GeneralAdvancedTechniques for an example).

    There is also no shakeScale, but I think you could probably get the same effect by passing a custom animation curve for the ease and using the scale method, something like:
    Code (CSharp):
    1. public AnimationCurve customAnimCurve; // edit this through the editor
    2.  
    3. void Start(){
    4. LeanTween.scale( gameObject, Vector3.one, 5f ).setEase(customAnimCurve);
    5. }
     
  5. Schromercy

    Schromercy

    Joined:
    Oct 26, 2013
    Posts:
    4

    Hello dentedpixel, your suggestion works perfectly! keep the good work! :)
     
    dentedpixel likes this.
  6. bzAdam

    bzAdam

    Joined:
    Aug 4, 2015
    Posts:
    35
    Hi I just tried using the "setFrom" (before I was doing a tween with 0 seconds to set the state) however there is a frame delay, so my panels show in full alpha and scale for a split second before changing to the "from" size and scaling in.

    The same happens if I do a tween with 0 time. I thought this had been fixed?

    Im using the latest version from github. Happens when referencing both gameobject and the rectransform.

    Thanks.
     
  7. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    This did come up as an issue awhile back, but sadly it has not been fixed, as it would require substantial reworking of LeanTween to make it happen. Sorry about that! I still may get to it, because the reworking involved could make the code a little better broken up.
     
  8. bzAdam

    bzAdam

    Joined:
    Aug 4, 2015
    Posts:
    35
    Ah thanks, I thought this has been an issue but thought it was fixed. I will continue to set my initial state manually now then (until theres an update :)) Thanks.
     
    dentedpixel likes this.
  9. shaneparsons

    shaneparsons

    Joined:
    May 5, 2015
    Posts:
    41
    Hey dentedpixel,
    Great job on LeanTween, I love that I was able to get it up and running in no time!

    I do have a question though:
    Between the 2 options below, do you see any benefit to using one over the other?
    Does tweening have more overhead than basic transforms?

    Code (CSharp):
    1. void Start()
    2. {
    3.     LeanTween.rotateAround(background, Vector3.back, 360, 20).setLoopClamp();
    4. }
    Code (CSharp):
    1. void Update()
    2. {
    3.     background.transform.Rotate(Vector3.back * 20 * Time.deltaTime);
    4. }
     
  10. dentedpixel

    dentedpixel

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

    Thanks! I am glad you are liking it :)

    It's hard to say if it has more overhead it may have slightly more overhead, because the tweens state is kept track of in the engine, but it is probably pretty negligible compared to a lot of the other things going on in the Unity engine or in your game code.

    It may even be better, because there is even a bit of a performance hit of doing things on the Update method. Since LeanTween only calls that method once it may actually be better in performance. But for the most part I wouldn't worry about this unless you are planning on doing thousands of tweens at once, or something seriously heavy.
     
    larku likes this.
  11. shaneparsons

    shaneparsons

    Joined:
    May 5, 2015
    Posts:
    41
    Ah perfect, thanks for shedding some light on it.
    Keep up the good work!
     
  12. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Hello dentedpixel,

    could you please add a uniqueId overload for LeanTween.value? Currently it's only possible to call with a GO.
     
  13. tonimarquez84

    tonimarquez84

    Joined:
    Feb 23, 2015
    Posts:
    17
    I'm having problems to compile a project:
    I've tried to put this:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3. #endif
    ...but is not working because there are more things in the LeanTween script that depends on this.

    ¿Anybody could help me, please? Thank's!
     
    Last edited: Jul 18, 2016
  14. tonimarquez84

    tonimarquez84

    Joined:
    Feb 23, 2015
    Posts:
    17
    I've fixed it by removing the documentation folder. SOLVED!
     
    Last edited: Jul 18, 2016
    dentedpixel likes this.
  15. Green-Jungle

    Green-Jungle

    Joined:
    Jun 10, 2014
    Posts:
    79
    HELLO.I'm having a problems with LeanTween scale on IOS.It's quite smooth on Android but not smooth on Iphone 5.
    public void ShowDialog()
    {
    LeanTween.scale(dialog, new Vector3(1.1f, 1.1f, 1.1f), .1f).setOnComplete(Blink);
    }

    private void Blink()
    {
    LeanTween.scale(dialog, new Vector3(1f, 1f, 1f), .1f).setRepeat(3).setLoopPingPong();
    }
    This is code show a Popup GUI .When I built it on iphone 5 then Popup lag.But on android is fine.Help me.thanks.
     
  16. djoshi

    djoshi

    Joined:
    Mar 28, 2014
    Posts:
    182
    Hi dentedpixel,
    I found a problem in ease type. I was trying to do value tweening from 0f to 100f & used easeInExpo. I noticed that after completion of tween value changes to 101.xxx, so every time it adds some number(which actually has to be 100f only). I get perfect 100f when I use linear type. I don't know if this is a bug or what but I think whatever easetype we use it should perform within given range only. Please let me know if there is a fix to this.
     
    Last edited: Jul 23, 2016
  17. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    211
    Last edited: Jul 25, 2016
    dentedpixel likes this.
  18. jinincarnate

    jinincarnate

    Joined:
    Mar 8, 2015
    Posts:
    2
    Hi downloaded and imported lean tween in my project but couldn't find the option to create 'leantweenpath'. Please help
     
  19. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Anyone knows if there is any difference between .id or .uniqueID?
     
  20. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    LeanTween bug:
    I'm using LeanTween to pulse some text (fade alpha to 0, then back to 1, wait, then back to 0...).


    Code (CSharp):
    1. public RectTransform m_target;
    2.  
    3. // This works perfectly and transitions from alpha 0 to alpha 1:
    4. _tween = LeanTween.textAlpha(m_target, 1f, .5f);
    5.  
    6. // However, this "snaps" from alpha 0 immediately to alpha 1:
    7. _tween = LeanTween.alpha(m_target, 1f, .5f);
     
  21. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    I should note that my end goal is to have a generic UI "ImagePulse" class with a few different options. I've attached the class here in-case anyone would like to use it. Everything seems to be in great working order, with the exception of this one bug (mentioned above).

    To use, just add this component to any object with a RectTransform.
     

    Attached Files:

  22. vladimirta89

    vladimirta89

    Joined:
    Jul 17, 2013
    Posts:
    39
    Hi dentedpixel.
    Great tween engine, thanks.

    I have one question.
    Is there any method to directly animate new UI RectTransform sizeDelta ?
    Or it is only with LeanTween.value (Vector2) ?
     
  23. Amonsat

    Amonsat

    Joined:
    Mar 26, 2015
    Posts:
    8
    Hi!!!
    Can I change speed later?
    I have LTDescr mover
    Code (CSharp):
    1. void Start ()
    2. {
    3.       mover = LeanTween.move(gameObject, targetPosition, 2f)
    4.             .setSpeed(speed)
    5.             .setRepeat(-1)
    6.             .setOnComplete(ClearCapacity)
    7.             .setOnCompleteOnRepeat(true);
    8. }
    And After I want
    Code (CSharp):
    1. mover.setSpeed(2f);
    But not anything change. How can I do this?
     
  24. aeonphyxius

    aeonphyxius

    Joined:
    Jun 16, 2013
    Posts:
    9
    Hi DentedPixel,

    We have updated Unity to 5.4 (from 5.3) and your plugin from 2.30 to 2.34.

    We were using the moveLocal function and among others, oriented to path. Everything was working fine till this last update that leaves the object oriented in the original position instead of the last position after the move action.


    The code we use look as follows:
    Code (csharp):
    1.  
    2.            tweenDescriptor = LeanTween.moveLocal(ActionObject, GetAdjustedPath(), GetTweenSpeed());          
    3.             tweenDescriptor.setDelay(startDelay);
    4.             tweenDescriptor.setEase(EaseType);
    5.             tweenDescriptor.setOrientToPath(OrientedToPath);
    6.             tweenDescriptor.onComplete = OnFinish;
    7.  
    Any idea what is causing this?:

    Thanks a lot in advance.

    (If needed I can post the values instead of var names / function calls), but it happens with different input values.
     
  25. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    580
    In your latest update LeanTween.alpha has issues. If many run at the same time one changes the other. Its not usuable. Had to switch to the older version with Unity 5.4p4.
     
  26. DarkPlan

    DarkPlan

    Joined:
    Jan 10, 2013
    Posts:
    15
    Hi,
    I've been using LeanTween in a few projects already and I love it!
    However in the latest version (or is it in the latest Unity?) it seems to be very buggy. Occasionally, tweens would not work correctly, like not call their onComplete delegates, or if set with a delay would not be called at all. 99% of the times they work as expected, then one would randomly not.

    For example I have an array of objects set to fly from one position to the other one after the other. They would all fly but then one of the objects would just get stuck on the middle of its tween. There is no script that handles these objects until they reach their destination with an OnComplete delegate.

    Another example is that I have a sound that I want to fade out with a 3 seconds delay. Sometimes it would work, sometimes it wouldn't.

    Just generally strange behavior. I thought that maybe it's a max tweens issue but I saw the default is 400 and I don't think I'm getting close to that number.

    We're in the middle of production with a live product and considering to move to a different tweening library if it's an impossible quick fix. I reeeaaaally don't want that! Not only it's a major refactoring I also just love the LeanTween API too much! DOTween just doesn't come close!

    Are these problems known? Is there a hotfix perhaps?
    Thanks!
     
  27. dentedpixel

    dentedpixel

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

    Sure thing, it's usually a good idea to associate a tween with a gameObject, just because things can get screwy if you switch scenes while it is tweening. But I have added it for those who know what they are doing. https://github.com/dentedpixel/LeanTween/tree/UpdatesOnTween/Assets/Plugins/LeanTween

    Sorry for the late response! I am just realizing my forum notifications are broken a month late :-/
     
    silentneedle likes this.
  28. dentedpixel

    dentedpixel

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

    I am not aware of any issues like that, but such a thing has been mentioned in the past, but it's never been pinpointed, or proven with recreatable steps.

    I have almost completed a massive overhaul of LeanTween, and I have added a bunch of Unit Tests to ensure everything is working properly. Would you like to give this new version a shot and see if it solves your problems? https://github.com/dentedpixel/LeanTween/tree/UpdatesOnTween/Assets/Plugins/LeanTween

    If you still have the issue and have any code you could share that recreate, that would be a huge help.

    Thanks!
    Russ
     
  29. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    You are right, there was a problem with setting it after the fact. I have fixed this, if you want to grab the latest from here: https://github.com/dentedpixel/LeanTween/tree/UpdatesOnTween/Assets/Plugins/LeanTween
     
    silentneedle likes this.
  30. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Giorgos_gs,
    Thanks for the heads up. Would you mind seeing if the same bug exists on this branch? https://github.com/dentedpixel/LeanTween/tree/UpdatesOnTween/Assets/Plugins/LeanTween . I have almost completed a major overhaul of the internals of the engine, and I am hoping that it solved this issue as well.
     
  31. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey NateJC,
    Sorry for the slow response! I have been working on a major reworking of the engine and it doesn't look like this is a bug anymore when I tried to reproduce it with your code. Could you check out the latest and let me know if you are still seeing a problem? https://github.com/dentedpixel/LeanTween/tree/UpdatesOnTween/Assets/Plugins/LeanTween

    Thanks!
    Russ
     
  32. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi djoshi,
    I think I have fixed this, I have been working on a major overhaul of LeanTween and I am almost done. I cannot recreate it in the latest. If you want to try the latest here and let me know if it is still an issue: https://github.com/dentedpixel/LeanTween/tree/UpdatesOnTween/Assets/Plugins/LeanTween

    Thanks,
    Russ
     
  33. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    580
    will check it
     
    dentedpixel likes this.
  34. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Hey dentedpixel,

    thanks for you answer. I have another question. How would you cancel the current tween inside setOnUpdate?
     
  35. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I think the same way you would cancel any tween should work:

    LeanTween.move( gameObject, new Vector3(0f,1f,2f), 1f).setOnUpdate( (float val)=>{
    LeanTween.cancel( gameObject );
    });
     
    silentneedle likes this.
  36. zeninja

    zeninja

    Joined:
    Jun 9, 2012
    Posts:
    8
    Hi! I just started using LeanTween. I'm trying to accomplish a cartoon bounce effect using LeanTween.value + the easeOutElastic easing. I'd like this to be a continuous tween so my code is as follows:

    Code (CSharp):
    1. void Update() {
    2. LeanTween.value(gameObject, SetSquashValue, squashValue, velocity.magnitude, Time.fixedDeltaTime).setEase(LeanTweenType.easeOutElastic);
    3. }
    4.  
    5. void SetSquashValue(float newValue) {
    6. squashValue = newValue;
    7. }
    It seems like this is a problem because LeanTween is telling me that I'm running out of allotted tweens. I've realized that I'm not meant to be starting a new LeanTween every frame, but I'm wondering if there's another way to do a continuous tween effect, something similar to iTween's ValueUpdate functions.

    Thanks!
     
  37. dentedpixel

    dentedpixel

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

    I am not sure you are going about this right, you are firing off a new tween on every frame, that only lasts a fraction of a second. You can have a callback method to get the updated value on every frame by using setOnUpdate http://dentedpixel.com/LeanTweenDocumentation/classes/LTDescr.html#method_setOnUpdate

    By continuous do you mean you want it to repeat? You can specify unlimited repeats with setRepeat( -1 ) http://dentedpixel.com/LeanTweenDocumentation/classes/LTDescr.html#method_setRepeat

    I hope that helps!
     
  38. Chusek

    Chusek

    Joined:
    Oct 9, 2012
    Posts:
    7
    Thank for the asset.!

    setting LTDescr.passed is not working when tween is paused. // using LeanTween version 2.34 -

    to clarify

    Let's say I'm tweening object movement from point A to B in 10 seconds

    A----------------------------------*-------------------------------------B

    descr.passed = 5f ; should and would put the object in the middle unless the tween is paused.


    Not sure if that's how it should be. It was working in previous version. // LeanTween version 2.32

    seems like the property is set but the actual position is not updated because the tween is paused.
    because once I resume the tween, the position moved to as previously set while paused using descr.passed
     
  39. alxcyl

    alxcyl

    Joined:
    Apr 15, 2015
    Posts:
    2
    How can I use LeanTween.alpha(RectTransform, float, float) with the alpha only affecting the specified rect transform and not its children? It was working fine in 2.29 but now in 2.34 it broke all my alpha tweens.
     
  40. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey there, you should be able to do .setRecursive(false); to make it not effect the children.
     
    DizzyWascal likes this.
  41. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Chusek,
    Would you mind checking if this works in version 2.40 (It is on Github but it is looking stable and ready for release soon: https://github.com/dentedpixel/LeanTween ). I am not sure why that may have stopped working, but before I investigate too much it may have been fixed in this latest version, because I refactored a ton of the internals.

    Thanks,
    Russ
     
  42. Chusek

    Chusek

    Joined:
    Oct 9, 2012
    Posts:
    7
    Hey Russ,
    Tried it, doesn't seem to work. Same behavior as I described with version 2.34.

    To illustrate clearly :

    Code (CSharp):
    1.  
    2.     void Start () {
    3.         descr = LeanTween.move(avatar1.gameObject, target.position, 10f);
    4.         descr.passed = 5f; // this should put it at the midway
    5.         descr.pause(); // doesn't matter if pause after or before setting descr.passed I think if I set the passed property and paused the next frame it would work
    6.     }
    7.     bool set = false;
    8.     void Update () {
    9.         if (Time.unscaledTime > 5f && !set)
    10.         {
    11.             descr.resume(); // once this execute the object is put at the midway position as setted by passed and the tween continue.
    12.         }
    13.     }

    Thanks,
    Chu
     
  43. dentedpixel

    dentedpixel

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

    I made an example scene trying out your code, you can see it on github: github.com/dentedpixel/LeanTween, just check out the scene LeanTween/Testing/TestinIssue.scene . It actually seemed to work, as far as I can tell with the latest code... so let me know if you see it differently.
    Thanks,
    Russ
     
  44. Chusek

    Chusek

    Joined:
    Oct 9, 2012
    Posts:
    7
    Hi Russ,

    Checked out your test scene. Doesn't work for me. Same as before.

    The passed property will only work when tween is resume. not when it's paused. I'm using Unity 5.4.1f1 .

    Thanks for your effort,
    Chu
     
  45. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Aaah, I didn't understand that wasn't the expected scenario. I added an updateNow method in case you want things to take effect immediately. You can check out that same example scene of how it was used (on github).
     
  46. Chusek

    Chusek

    Joined:
    Oct 9, 2012
    Posts:
    7
    Thank you very much for your work.

    This works :
    Code (CSharp):
    1. descr.passed = 5f;
    2. descr.updateNow();
    3. descr.pause();
    This doesn't
    Code (CSharp):
    1. descr.pause();
    2. descr.passed = 5f;
    3. descr.updateNow();
    4.  
    It works in case you want to set passed before pausing. But not when you want to move object around when paused.

    while the obvious work around would be to resume() then set passed and updateNow() then pause().

    or position the object manually through transform position while also setting passed property, once resumed it just continue from that position.

    I'm using the latter. So it's no big deal but I guess it might be nice to have.

    Thanks again man.
     
  47. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Last edited: Oct 11, 2016
    ZJP likes this.
  48. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,646
    Thanks :cool:
     
  49. musspell

    musspell

    Joined:
    Oct 17, 2015
    Posts:
    7
    Hello,
    This is by far the best tween engine I used in Unity. Thanks for your hardwork.
    I just have some basic questions I couldn't figure out by reading the documentation.

    Is there any way to restart a completed tween or a canceled tween. I mean replay it from the beginning without creating a new Descr?

    To restart an unfinished tween I'm using the 'passed' var and its working fine, like this:
    Code (CSharp):
    1. if (LeanTween.isTweening(m_Tween.id)) {
    2.           m_Tween.passed = 0;
    3. }
    But if the tween is already completed or cancelled this does not work anymore and I can't find any method to restart the tween from the beginning. Is there some way to do this or the solution is to create a new descr? Also, for efficiency, after a tween is completed should we cancel it manually or we can leave it?

    Just to be more clear, what I'm trying to achieve is not a clamp loop that replays all the time. I just want to restart the tween when the user clicks on a button.

    Thank you!
     
  50. XenoRo

    XenoRo

    Joined:
    Jul 22, 2014
    Posts:
    23
    Hi dentedpixel!
    First of all, I want to thank you for the tweening engine! It's (very, very) AWESOME! I have just started using it, but it has already aided me a LOT with some of the stuff I wanted to do with my first game, and that weren't (for a total beginner like me) being easy to accomplish.

    I have a little doubt that I'm not finding any answer that makes sense to me, and I think it's probably something easy, maybe even obvious, that I'm just missing. I want to trigger an event/action at the end of a tween. I suspect that the (best?-ish?) way to do this would be using the event dispatcher(?), but how?

    To be more detailed, I'm making a "breakout meets space-invaders" -like game... Pretty much a clone of the game mechanics of 111% studio's "BBTAN" game, with some of my own touch added on top. My trouble is with switching from one state to the next... I have made a simple class-based state-machine with states that have "OnEnter()" and "OnExit()" abstract methods, to use in my game-manager, and I want to, for example, only switch to the "user-input" state when all animations (tweens) from the "performing turn" state are over.
     
    Last edited: Oct 20, 2016
unityunity