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:
    343
    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:
    93
    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:
    343
    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:
    35
    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:
    9
    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:
    80
    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:
    197
    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,601
    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:
    95
    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:
    829
    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:
    829
    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,601
    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:
    14
    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:
    93
  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:
    700
  21. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
  22. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    @Johannski LeanTween allocates around 4.5mb on the launch of the game. Is it normal?
    upload_2020-2-10_11-52-38.png
     
    yuliyF and DarkCooker like this.
  23. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Hi @sathya

    No, I would definitely say that is not normal. I just did a quick heck for the GeneralBasic scene with Unity 2019.3 and enabled experimental PlayMode:

    upload_2020-2-10_11-34-3.png

    I also added a Profiler Sample to easily profile the init code. 260KB is still not nothing, but kind of necessary, since we're creating quite a few arrays at the very beginning. This init code also happens only once each Play.

    Can you try to run the GeneralBasic Example scene and give me a bit more background on your Test (Editor or on Platform, Unity Version, Mono or IL2CPP).
     
  24. K0ST4S

    K0ST4S

    Joined:
    Feb 2, 2017
    Posts:
    35
    I want to use LeanTween methods with async Task (in order to await execution end). Is it possible to make thread wait for tweening end?

    Edit: I solved it by passing event invocation action to setOnComplete() and awaiting that event.
     
    Last edited: Mar 25, 2020
  25. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    Just use setOnCompletion(() => {<your completion code here>}) on the tween.
     
  26. paul-velocity

    paul-velocity

    Joined:
    Oct 20, 2012
    Posts:
    18
    HELP!

    Cant even get lean tween to be recognised .. what am i doing wrong here:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using DentedPixel;
    5.  
    6.  
    7.  
    8.  
    9. public class Rotater : MonoBehaviour
    10. {
    11.     public GameObject avatarRotate;
    12.  
    13.     void Start()
    14.     {
    15.  
    16.         //   transform.Rotate.transform  (Time.speed, 0, 0,);
    17.         GameObject avatarRotate = GameObject.Find("Rotate");
    18.         LeanTween.rotateAround(avatarRotate , Vector3.forward, 360f, 5f);
    19.  
    20.     }
    "The name leantween does not exist in this context"

    Tried with and without : using DentedPixel; or using LeanTween.

    Then 2 errors at compile:

    Assets\Scripts\Rotater.cs(18,9): error CS0103: The name 'LeanTween' does not exist in the current context
    Assets\Scripts\Rotater.cs(18,32): error CS0103: The name 'Rotate' does not exist in the current context
    etc

    Yet the example scenes work fine ..... what am i doing wrong?
     
    Last edited: Apr 13, 2020
  27. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Your example code is correct. The errors say that you're missing LeanTween. I see two possible causes: You haven't included LeanTween in your project or there is another compile error that stops unity from importing LeanTween.

    Is there an error in edit mode if you clear the console? If so, you first need to fix that error.
     
  28. NotMyUsernameAgain

    NotMyUsernameAgain

    Joined:
    Sep 28, 2017
    Posts:
    139
    Hi everyone,

    is there a way to change the Color of an Image component, ie the canvas UI?
    When I use "LeanTween.color" it is asking for GameObject as parameter, and if I use that GameObject no visual change happens.

    Also, I'm using this way to check if a tween has finished, for my coroutine. Is this correct?
    Code (CSharp):
    1. while (LeanTween.isTweening(quizBox)) { yield return null; }
    EDIT:
    OK, found it.
    need to pass the RectTransform component
     
    Last edited: Apr 23, 2020
  29. Karlbovsky

    Karlbovsky

    Joined:
    Jul 11, 2012
    Posts:
    231
    Hi everyone,
    I was wondering if there is a way to have LeanTween as a unity package with its own asmDef instead of an asset store package !?
     
  30. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Yep, I made a fork for packaging it: https://github.com/JohannesDeml/LeanTween
    You can also get it through openupm if you want to :)
     
    Karlbovsky likes this.
  31. Karlbovsky

    Karlbovsky

    Joined:
    Jul 11, 2012
    Posts:
    231
  32. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    275
    Hey, can anyone help? I just imported LeanTween for the first time in an existing project and I'm getting 72 Errors from LeanTween, this is the first one:
    Assets/LeanTween/Examples/Scripts/GeneralBasic.cs(32,43): error CS1503: Argument 3: cannot convert from 'method group' to 'Action'

    32:
    LeanTween.delayedCall(gameObject, 0.2f, advancedExamples);
    All errors come from either
    Assets/LeanTween/Examples/
    or
    Assets/LeanTween/Framework/


    It seems like scripts are not able to see each other when inside another folder anymore. I feel like my Visual Studio is completely F***ed up, I have sketchy problems like scripts not finding references or assemblies and all this stuff often the last weeks. Maybe someone knows what to do?

    I already tried deleting the project and solution files and letting Unity Regenerate project files in Preferences.
     
    Last edited: May 19, 2020
  33. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    226
    Hello all, I'm new to LeanTween and tweeting in general, and can only applaud it so far. I have one question though, If I am setting a Game Object to tween and then destroy the object, do I need to cancel the tween beforehand? For example, if I have a Game Object set to loop indefinitely with a tween, then destroy the object either manually, or with a scene change, could that cause any potential errors or memory leaks? Thanks.
     
  34. HNKMaster

    HNKMaster

    Joined:
    Aug 31, 2012
    Posts:
    19
    Hi, I want to know if I can get the current velocity (vector3) and direction of an object being moved with Leantween?
     
  35. BryanCote

    BryanCote

    Joined:
    Mar 26, 2020
    Posts:
    1
    Having same issue. Did you figure it out?
     
  36. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    I'm updating some older projects, and I see that LeanTween hasn't been updated since October, 2018. Is LeanTween still being supported? Will is receive future updates? I'd like to future-proof my projects as much as possible, and if I'm going to have to switch animation engines (yet again), I'd rather do it now during this update cycle rather than put it off. Thanks.
     
  37. Hungry-Lion

    Hungry-Lion

    Joined:
    Sep 2, 2018
    Posts:
    21
    Hi, can we use this to change the alpha value on a UI image element? Like a fade in fade out.
     
  38. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    226
    Looks like the answer is to use DoTween
     
  39. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    There is an updated package manager version of LeanTween on Github. It still works fine. I don't like DoTween because it's way more complicated and adds a lot of API bloat to your project and has an editor integration with some weird setup step you have to go through before you use it. Why? I would rather just have the code and not have yet another menu in my Unity editor.
     
  40. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    226
    That's true.
     
  41. jasonrbrock

    jasonrbrock

    Joined:
    May 22, 2019
    Posts:
    15
    Hi, just started receiving "LeanTween - You have run out of available spaces for tweening." errors.
    Understand a fix is to increase the number of spaces available, but this seems like a band-aid fix, anyone debugged and fixed this without changing the 800 spaces value?
     
  42. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey can anyone tell me why this won't fade an audiosource volue to 0?

    Code (CSharp):
    1.     public AudioSource m_audiosource;
    2.  
    3.     // Start is called before the first frame update
    4.     void Start()
    5.     {
    6.         LeanTween.value(gameObject, m_audiosource.volume, 0.0f, 3f).setOnComplete(() =>
    7.         {
    8.             Debug.Log("Done");
    9.  
    10.         });
    11.  
    12.  
    13.     }
     
  43. CWatsonT2

    CWatsonT2

    Joined:
    Jan 9, 2019
    Posts:
    114
    Can you use lean tween to move something without setting the time? I need things to move a set speed. I'm currently using iTween and it lets you set a speed instead of a time. Is this possible with lean tween?
     
  44. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    @dentedpixel ?
     
  45. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    Can someone please clarify to me what the first and last values in LTSpline do and what they are used for? I have a collection of waypoints that I want a character to move along, without using navigation mesh. I tried
    Code (CSharp):
    1. Vector3[] waypoints;
    2. float time;
    3. LeanTween.Move(gameObject, waypoints, time)
    but it gave me an error (I can't recall what error it was).
    Then I tried
    Code (CSharp):
    1. Vector3[] waypoints;
    2. float time;
    3. LeanTween.moveSpline(gameObject, waypoints, time);
    And it kind of worked but the character didn't reach the last waypoint. Then I added two extra Vector3 variables at the beginning and at the end of the array and it works now! What I don't understand is what those two variables are used for? Documentation says the following:
    ,
    but I'm still struggling to understand when and why it might be used. Can someone give me an example, please.
     
  46. zackblack

    zackblack

    Joined:
    May 17, 2015
    Posts:
    76
    I just purchased LeanTween Editor on the asset store for use in Unity 2019.4. When I try to add a Tween to a new Group it starts throwing null reference errors. Is there a fix for this?
     
  47. JeffNIAR

    JeffNIAR

    Joined:
    Jan 13, 2016
    Posts:
    8
    Is it possible to control the tangent directions numerically for the start and stop, or at least visualize them with a gizmo? I am trying to match some paths together and there is slight hiccup due to the tangentcy mismatch. Example, car moves forward going to the right, stops, and then goes backwards to the left. Kind of like a 2 point turn.
     
  48. aadityakirans

    aadityakirans

    Joined:
    Jan 3, 2020
    Posts:
    2
    Hi, enjoying your package. I was wondering if there was any way to change the speed of a tween while it was in progress? I have a 2D game that I'm working on which has a conveyor belt system. I need to change the speed of it at will. I had started to implement the movement of the items on the conveyor through tween. I can't see a way to change the speed in between tweening. Is that possible? Is that something that you could implement?
     
  49. iftah

    iftah

    Joined:
    Feb 25, 2014
    Posts:
    16
    Thank you for your great asset, I am trying to move an object through a set of points using a linear path, I used the move function with the easing type LeanTweenType.linear, but the path generated by LeanTween is not linear, am I missing something?
    Thanks a lot for your help.
     
  50. Asad-Mehar

    Asad-Mehar

    Joined:
    Aug 17, 2015
    Posts:
    4
    Hi, anyone knows how to use LeanTween to animate an object even when timeScale is set to zero?
    For example:- this line of code doesn't work if the time.scale is zero. Is there any flag/function to ignore timeScale?
    LeanTween.move(gameObject.GetComponent<RectTransform>(), destPos, timeAnim).setEase(_animType);