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

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    146
    I have a ~LeanTween that is not being destroyed and is carried along through scene changes. I am initiating it in a coroutine if that's an issue. Is there a way I can destroy it manually? I tried to check the docs but the website seems to be offline.

    Code (CSharp):
    1. public IEnumerator HomeCheckmarkGo()
    2. {
    3.     LeanTween.alpha(homeCheckmark.GetComponent<RectTransform>(),
    4.                     1f, 0.2f).setEase(LeanTweenType.easeInQuad);
    5.     LeanTween.scale(homeCheckmark, new Vector3(1.8f, 1.8f, 1.8f),
    6.                     0.1f).setEase(LeanTweenType.easeInQuad);
    7.     yield return new WaitForSeconds(0.12f);
    8.  
    9.     LeanTween.scale(homeCheckmark, new Vector3(1f, 1f, 1f),
    10.                     0.08f).setEase(LeanTweenType.easeInQuart);
    11.     yield return new WaitForSeconds(2.2f);
    12. }
     
  2. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    48
    You probably want something like this:

    Code (CSharp):
    1.  
    2. private LTDescr _tween1;
    3.  
    4. public IEnumerator HomeCheckmarkGo()
    5. {
    6.      if (_tween1 != null)
    7.      {
    8.           LeanTween.cancel(_tween1.id);
    9.           _tween1 = null;[/INDENT]
    10.      }
    11.  
    12.      LeanTween.alpha(foobar).setEase(LeanTweenType.easeInQuad).setOnComplete(delegate ()
    13.      {
    14.          _tween1 = null;
    15.      });
    16. }
    17.  
    Please check if this works. I did not test this myself, so I'm not sure if the coroutine can cause issues on tweens.
     
  3. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    146
    Thanks for the code. I couldn't get it to work at first but then discovered there's a lot more going on than I thought. All tweens in all scenes will create a ~LeanTween object but there is never more than one existing at a time. It's not causing any problems so I'm inclined to ignore it for now.
     
  4. kactus223

    kactus223

    Joined:
    May 20, 2014
    Posts:
    24
    Recently I got multiple Array index out of range exception in LeanTween, most of them come from method cancel.

    Code (CSharp):
    1. public static void cancel( GameObject gameObject, bool callOnComplete, TweenAction matchType = TweenAction.NONE ){
    2.         init();
    3.         Transform trans = gameObject.transform;
    4.         for(int i = 0; i <= tweenMaxSearch; i++){
    5.             LTDescr tween = tweens[i];
    6.             if (matchType == TweenAction.NONE || matchType == tween.type) // only match the type if it is specified to a value other than none
    7.             {
    8.                 if (tween != null && tween.toggle && tween.trans == trans)
    9.                 {
    10.                     if (callOnComplete && tween.optional.onComplete != null)
    11.                         tween.optional.onComplete();
    12.                     removeTween(i);
    13.                 }
    14.             }
    15.         }
    16.     }
    I tried debuging and found that the error happens when tweenMaxSearch reaches 400, which equals to the size of tweens array. I'm not sure if I did something wrong.
     
  5. monoRAIL

    monoRAIL

    Joined:
    May 22, 2010
    Posts:
    4
    I noticed Leantween.alpha() also fades the alpha of children of the gameobject. This was very inconvenient, I had to temporarily unlink all the children so I could do the tween and then re-link them. It would be nice to have an optional boolean argument to not tween children:

    Leantween.alpha(gameObject, 1, 1, false); // don't tween children
     
  6. spvn

    spvn

    Joined:
    Dec 10, 2013
    Posts:
    35
    Hey I'm currently using LeanTween to move to a transform. What's the easiest way to handle the target transform being destroyed? Ideally, what I want is for the object to be tweened to the transform, but if the transform is destroyed while the tween is running, then change the end value so that it tweens to the transform's last position before it was destroyed. Is there any way to achieve this?
     
  7. Vonwarr

    Vonwarr

    Joined:
    Jul 19, 2013
    Posts:
    2
    I'm using LeanTween and overall it's great, but I wanted to bring up a couple of points:

    I'm using LTBezierPath to move 2d sprites around. When using
    .setOrientToPath2d(true);
    the sprite is forced to face perpendicular to the motion. Why is that? I was poking at LTBezierPath's place2d function and came up with the following:
    Code (CSharp):
    1. public void place2d( Transform transform, float ratio ){
    2.     transform.position = point( ratio );
    3.     ratio += 0.001f;
    4.     if(ratio<=1.0f){
    5.         Vector3 v3Dir = point( ratio ) - transform.position;
    6.  
    7.         // Orients the sprite to the direction it is traveling
    8.         transform.up = v3Dir;
    9.  
    10.         // Previous method, sets orientation perpendicular to the path
    11.         //float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
    12.         //transform.eulerAngles = new Vector3(0, 0, angle);
    13.     }
    14. }
    15.  
    Or alternatively, perhaps allow for an path orientation offset to be used for 2d?
    Code (CSharp):
    1. public void place2d( Transform transform, float ratio ){
    2.     transform.position = point( ratio );
    3.     ratio += 0.001f;
    4.     if(ratio<=1.0f){
    5.         Vector3 v3Dir = point( ratio ) - transform.position;
    6.         float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
    7.         var offset = 90; // Pass this into the function instead?
    8.         transform.eulerAngles = new Vector3(0, 0, angle - offset);
    9.     }
    10. }
    11.  
    These were really quick hacks, I would love to hear if there is a reason why the perpendicular orientation is required or why my line of thought is wrong/not performant. I would really prefer not to have to change my GameObject hierarchy to orient to a path, as appears to be the current solution.

    As an aside, the documentation on http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html is very out of date.
     
  8. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    144
    Code (CSharp):
    1.  var seq13 = LeanTween.sequence();
    2.         seq13.append(5f);
    3.         seq13.append(LeanTween.moveLocalY(IcoGold, 100, 1f).setEase(LeanTweenType.easeInElastic));// .setRepeat(-1)
    4.         seq13.append(0.1f);
    5.         seq13.append(LeanTween.moveLocalY(IcoGold, 0, 1f).setEase(LeanTweenType.easeInElastic));
    Can I repeat sequence ? Like this : sequence .Repeat() .. or something
     
    wangzy_88 likes this.
  9. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,385
    Hi
    the following works great to create a sort of vertical vibrating motion.
    My problem is the amount of movement. Is there any way to make the y value parameter (0.4f in the example) relative instead of absolute?

    Code (CSharp):
    1. LeanTween.moveY(gameObject, 0.4f, 0.2f).setEase(LeanTweenType.easeShake).setLoopClamp().setRepeat(-1);
     
  10. Jinxology

    Jinxology

    Joined:
    Jul 13, 2013
    Posts:
    59
    Ugh, I'm struggling with something that I'm sure is easy. I'm using .moveSpline(), and I need the sprite to start at a random point along the path. How do I do that?! If I use .place2d after the moveSpline, it doesn't seem to do anything. I'm assuming that moveSpline will immediately overwrite that position.

    Code (CSharp):
    1.            
    2. Vector3[] pts = { new Vector3(631, 194, 0), new Vector3(631, 194, 0), new Vector3(298, 369, 0),
    3.                 new Vector3(324, 179, 0), new Vector3(625, 388, 0), new Vector3(631, 194, 0), new Vector3(631, 194, 0)};
    4.  
    5. LTSpline path = new LTSpline(pts);
    6.  
    7. LTDescr spline = LeanTween.moveSpline(gameObject, path, 6f).setEase(LeanTweenType.linear).setLoopCount(999999).setLoopType(LeanTweenType.linear);
    8.  
     
  11. TylerO

    TylerO

    Joined:
    Aug 21, 2011
    Posts:
    35
    I have a question, might have been answered before but can't seem to find an answer via Google search.

    I am setting the timeScale to a lower value (to achieve a slow motion effect) and it seems LeanTween isn't slowing down.

    Am I forgetting to do something? I am started the tween before the timeScale is changed, maybe I need to update something with my tween after changing the timeScale?

    I appreciate any help!
     
  12. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    786
    Use tween.setIgnoreTimeScale (true).
     
  13. TylerO

    TylerO

    Joined:
    Aug 21, 2011
    Posts:
    35
    Thanks for the quick reply. Unfortunately, that didn't seem to do the trick. I was a bit confused by passing in true (wouldn't that make it ignore the timeScale and thus not slow down when I am editing timeScale?) so I tried false as well, but still - no luck.

    It's worth noting that I am using
    LeanTween.value()
    to call a method that uses
    Rigidbody.MoveRotation()
    so maybe value doesn't support what I am thinking it should support?

    Again, thanks for the quick reply!
     
  14. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    786
    Ah sorry, I misread. I believe that default LeanTween behaviour is to scale time progression with time scale, so this parameter is only needed for unscaled tweens. Weird that it's not behaving the same way for you - I'm using LeanTween pretty much exclusively for custom value tweening methods. Maybe I did some modifications related to time scaling at some point and forgot about them, sorry! :)
     
  15. TylerO

    TylerO

    Joined:
    Aug 21, 2011
    Posts:
    35
    No worries!

    I've been going through the LT code and on initial glance, it seems like it should work fine, as the default 'delta time' that it seems to use (in my case) is Time.deltaTime.

    But obviously I am missing something!

    Thanks for the help, hopefully the author will be around and might have some more insight!
     
  16. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,385
    Just imported latest version to a HDR pipeline using 2019.2.1f1 and getting a lot of strange errors.
    Especially this one

    The name 'LeanSmooth' does not exist in the current context

    What is going on?
     
  17. Vak_HD

    Vak_HD

    Joined:
    Aug 6, 2016
    Posts:
    13
    Anyone know how I could add a parameter so I could choose weather or not to use Time.deltaTime or Time.unscaledDeltaTime for when using calls to like LeanTween.scale() or LeanTween.move()

    Asking this for when using for UI when the game is in a paused state.

    Thanks.
     
  18. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    48
  19. luke1513

    luke1513

    Joined:
    Sep 19, 2018
    Posts:
    5
    Hello. I am animating some cars with Lean Tween and I want them to slow down. Not using .pause() of course, as that instantly stops them. I tried to use Lerp() with the parameter in the .setSpeed() function, slowly decreasing the speed to zero but it's a mess, to the point where it goes backwards. I can't use easing because I need the car to stop sometimes in the middle of the path. Any ideas?
     
  20. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    498
  21. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    617