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

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    You can ignore the timescale via ".setIgnoreTimeScale(true)"
     
  2. Doppio_movimento

    Doppio_movimento

    Joined:
    Jan 9, 2016
    Posts:
    12
    This is old, but leaving this here in case it helps anyone:
    Code (CSharp):
    1. LeanTween.value(gameObject, m_audiosource.volume, 0f, 3f)
    2.     .setOnUpdate((float volume) =>
    3.     {
    4.         m_audiosource.volume = volume;
    5.     }).setOnComplete(() =>
    6.     {
    7.         Debug.Log("Done");
    8.     });
     
  3. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    LeanTween is really cool, but last release were 2 years ago.. maybe will be updated? Some new futures..)))
     
  4. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    Please no, don't try to fix it if its not broken. We don't want to turn it into a bloated mess like DOTween.
     
    yuliyF likes this.
  5. Clickys

    Clickys

    Joined:
    Feb 25, 2017
    Posts:
    3
    Greetings fellow devs,

    Is it worth trying LeanTween assets or are outdated and not worth it to use it in my new project?
     
  6. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    While it is not in active development anymore, LeanTween is stable and has everything you would wish for in a Tweening engine (including sequences). I made a small fork with UPM support and Direct Enter Play Mode.

    On the other hand, if you're just starting with tweening, I would recommend DoTween, since it has an active developer.
     
  7. lasaterz

    lasaterz

    Joined:
    Feb 22, 2021
    Posts:
    1
    Is there a way to set this globally?

    Thanks!
     
  8. cyangamer

    cyangamer

    Joined:
    Feb 17, 2010
    Posts:
    234
    The LTSeq feature is nice, but I found a bug with it. Intermittently (on average 1 every 20 times), the action paired with the "Debug.Log(Teleporting upwards);" statement is completely skipped and the sequence continues without that critical movement action. The intent to teleport the gameobject and continue the sequence.

    pieces[3] is a GameObject

    I read that's this isn't in active feature development anymore, but are bug fixes / maintenance still being done?

    Code (CSharp):
    1. private void RamPlayer()
    2.         {
    3.             var seq = LeanTween.sequence();
    4.             float z = pieces[3].transform.localPosition.z;
    5.             LeanTween.pause(horizTweenId);
    6.             seq.append(() =>
    7.             {
    8.                 ramming = true;
    9.             });
    10.             seq.append(0.5f);
    11.             seq.append(() => MasterAudio.FireCustomEvent("cookie_wedge_woosh", pieces[3].transform));
    12.             seq.append(LeanTween.moveLocalZ(pieces[3], pieces[3].transform.localPosition.z - 50f, 1.67f).setEase(LeanTweenType.easeOutExpo));
    13.             seq.append(() => {
    14.                 pieces[3].transform.localPosition = new Vector3(0, 0, 20);
    15.                 Debug.Log("<color=#FFAA22>Teleporting upwards</color>");
    16.                 });
    17.             seq.append(0.5f);
    18.             seq.append(LeanTween.moveLocalZ(pieces[3], z, 2f).setEase(LeanTweenType.linear));
    19.             seq.append(() => { LeanTween.resume(horizTweenId); });
    20.             seq.append(1f);
    21.             seq.append(() =>
    22.             {
    23.                 ramming = false;
    24.             });
    25.         }
    EDIT: Forgot to clarify: I'm using the most recent version (version 2.50)
     
    Last edited: Apr 4, 2021
  9. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    I took a quick look at the source code. LTSeq does not finish one element anf then move to the next (as you would might expect), but creates an entry for every tween with a time offset which is set in the list of tweens. So you can be sure, that a tween will run before or after another tween, when they run on the same time (in your case movelocalz and the debug function).
    Seems like an annoying limitation which results in unexpected behavior. Changing this would create the need to completly change how sequences work in LeanTween. That's the bad news. But I also have good news for you: There is a function called onSetComplete, which will run after the tween has finished and therefore will always run after the last change of moveLocalZ. Try to change line 12-16 to
    Code (CSharp):
    1. seq.append(LeanTween.moveLocalZ(pieces[3], pieces[3].transform.localPosition.z - 50f, 1.67f).setEase(LeanTweenType.easeOutExpo)
    2. .setOnComplete(() => {
    3.     pieces[3].transform.localPosition = new Vector3(0, 0, 20);
    4.     Debug.Log("<color=#FFAA22>Teleporting upwards</color>");
    5.     })
    6. );
     
    jRocket likes this.
  10. nindim

    nindim

    Joined:
    Jan 22, 2013
    Posts:
    130
    Hi,

    I realise this asset is no longer supported by @dentedpixel, but maybe someone else can help or advise if I'm doing something wrong?

    My issue seems to be similar to this issue that was supposed to be fixed here in that delays continue to countdown for paused Tweens.

    I am setting up all my tweens in advance using LeanTween.delayedCall, I then immediately call LeanTween.pause(id) to prevent the animations from actually playing until I am ready a bit later on.

    I have noticed that the delay is eaten up while the tween is paused which is definitely not expected from my POV. I tracked the problem down to this code in LTDescr:

    this.delay -= dt;

    https://github.com/dentedpixel/Lean...2/Assets/LeanTween/Framework/LTDescr.cs#L1014

    In the normal update block the dt is scaled by directionLocal which is what actually does the pausing:

    https://github.com/dentedpixel/Lean...22/Assets/LeanTween/Framework/LTDescr.cs#L984

    Is there another way to pause Tweens that also pauses the delay?

    Thanks a lot!
     
  11. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    Hello,
    I am begining to use LeanTween, and it works great so far, except for something i don't understand:
    I use a LeanTween to change the alpha of an image, it works as expected, but at the end of the tween action, when i check in the profiler, i still get:
    LeanTween.Update()[Invoke]
    it's like the tween never get terminated, and when i want to change the alpha value that is changed by tween, i can't, it reacts like the tween is allways attached to it, not over.
    my code is:

    Code (CSharp):
    1. LTDescr LeanAlphaText(Image image, float to, float time)
    2.     {
    3.         var _color = image.color;
    4.         var _tween = LeanTween
    5.             .value(image.gameObject, _color.a, to, time)
    6.             .setOnUpdate((float _value) => {
    7.                 _color.a = _value;
    8.                 image.color = _color;
    9.             });
    10.         return _tween;
    11.     }
    What am i doing wrong ?
     
  12. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    Here is a question that might sound weird.
    I have this installed. My question is: 'Does one have to write code to get this to work or how are the gameobjects and scripts parented to make an object to follow a tween built in the path editor?'
     
  13. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    How about an update so alphaText works with TextMesh Pro?

    FYI, the file that needs to be changed is LTDescr.cs.
     
    Last edited: Sep 17, 2021
  14. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I got my version to work in a new Unity version. It works now. But if you have problems or needs you wont get answers.
    The dev has left the ranch.
     
  15. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    The forked version on github seems to work fine on newer versions of Unity, but it would be nice to have new features. I like LeanTween because it's unobtrusive, lightweight, and easy to use. Are there any similar tweening libraries that are being actively maintained and not called DoTween?
     
  16. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    Do you have a link? The only one I can find looks like the original, updated 3 years ago. No problems for me in Unity 2020.
     
  17. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
  18. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    I can't get that OpenUPM installation to work (-bash: npm: command not found). Is there anywhere I can just download a regular Unity asset package that doesn't require additional steps to install?
     
  19. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    Just download a last release : https://github.com/JohannesDeml/LeanTween/releases/tag/2.50.4
     
  20. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Yep, exactly. You can either use the download or install openupm (which is a great tool to be honest). The requirement for openupm is npm, which you can get here: https://nodejs.org/en/

    As for new features: I'm always happy to take PRs. I'm not using LeanTween in any current project, so it won't be that high of a priority for me to develop it further, but if there is a feature a lot of people need, I can take a look if I find the time to implement it :)
     
    yuliyF likes this.
  21. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    That zip uncompresses to a folder with 44 more folders inside it with names that look like random strings of characters. Nothing that looks like a Unity package, nothing Unity will import.

    I did find an archive called LeanTween-master 2.50.4 that looks like the source. I think I can get it working from that, copying files one at a time. I was just hoping for a standard asset package.
     
    Last edited: Jul 30, 2021
  22. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Not quite sure what you downloaded, but I packaged them in a standard unity package.
    firefox_S1tORUliyP_LI.jpg

    I attached the unitypackage now to this post as well, if you still have problems with downloading it from github.
     

    Attached Files:

    yuliyF and jRocket like this.
  23. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    Thanks. That decompresses to a single file, a Unity package.

    LeanTween-2.50.4.unitypackage.zip is the file I downloaded, more than once. Several copies are still in my trash. Is that maybe a file format (zip?) that my Mac doesn't know how to decompress? I noticed every time I tried to unzip it, there were briefly two folders on my desktop, then one of them disappeared, and all that was left was the folder with lots of random files.
     
  24. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Oh, very interesting. Just tried it on mac, and I have the same problem. .unitypackage is also nothing more than a zip, so you're seeing the contents of the unitypackage, but it is interesting, that archive decides to automatically unpack it.

    Thanks a lot for letting me know, a lot of my published open source projects pack unitypackages insde zips (I think github didn't allow .unitypackage as an extension previously). I will look into this :)
     
    John-B likes this.
  25. BhattacharyaKun

    BhattacharyaKun

    Joined:
    Mar 23, 2019
    Posts:
    1
    Hello,

    I'm having issues with Object Movement and Rotation. They stutter/lag/jerk while animating. I tried the entire internet, discord and everywhere and I didn't find any solutions. Please hit me up if anyone knows why is this happening.
     
  26. Posey1

    Posey1

    Joined:
    Nov 18, 2018
    Posts:
    3
    Is there a pdf version of the documentation?? The website isnt working.
     
  27. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I am assuming the dev has gone away. He answers no more.
    I am in 2020.3.4f1 and used it. It works. LT seems to be a complete finished asset. In fact so complete that it just simply works.
    I had previous problems with it not showing up in the Unity menu in I believe a Unity ~2017(some where there).
    In 2020.3.4f1 it then resumed to show up in the menu and now I use it. Havent run into any bugs yet.
    But this is current. Problems could crop up.
     
  28. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    Hey guys... I really like this asset and have been using it throughout the years. I also have doTween (payed version) but have not really used it. So it looks like developer abandon this project or got hit by a bus (who knows). Haven't heard from him for a long time. Wanted to ask for your recommendation, should I move to doTween. I mean, Lean still works for now but eventually there might be problems and I have other things to code than tween code. Thoughts????

    And to the Lean Tween developer. Thank you for this asset, I've used it many times. You own us nothing.
     
  29. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    It is open-source on github now, with support for newer Unity versions and package manager support. So, I would say no need to switch if you prefer using Leantween.
     
  30. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    Hmm. I'll take that into consideration. Thanks.
     
  31. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    I was able to make the necessary changes in an older version of LT, but after updating, it no longer works. Now when I add "Using TMPro" at the top of the LTDescr.cs file, it tells me, "the type or namespace TMPro cannot be found." Any suggestions on how to get the text-related LT functions to work with TMPro text?

    I had been using LeanTween.value to change the alpha value of TMPro text, but that doesn't work after converting from UnityScript to C# – Argument 2: cannot convert from 'method group' to 'Action<float>'.
     
    Last edited: Sep 25, 2021
  32. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    You probably know this but TMPro used to be an asset before Unity bought it. Now it's part of the package manager, I'm guessing there might be some info/guidance on how to reference namespaces between packages that were applied via package manager.
     
  33. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    As @JesterGameCraft already noted, this is due to the package changes. Each unity package requires to have its own assembly definition file to work as a package. This is great, because the package does not need to be recompiled as long as there are no changes in the package code (which does not normally happen until you pull the next version of a package) and none of the referenced assemblies change. The assembly definiton file we're talking about is this one:
    upload_2021-9-28_8-9-12.png
    You can do three things now:
    1. Since you're using the package inside your assets, you could remove the optimization of assembly definition files to have all the freedom you had before. For that, you just need to delete the com.leantween and com.leantween.editor assembly definition files. Afterwards, everything is, as you are used to again.
    2. You can also reference the text mesh pro assembly defintion file, in order to access its namespace. This keeps the optimization for not recompiling this code part whenever you change other stuff.
      upload_2021-9-28_8-14-8.png
    3. You can also decide not to touch the package itself, but add your code inside your project, if that is an option. This way, you don't need to touch the package content itself and can update without destroying your work. However, since leantween development is not active, this might be not as important.
     

    Attached Files:

  34. Lagonas

    Lagonas

    Joined:
    Jul 13, 2017
    Posts:
    2
    Hey my friends, I have a question: I am currently using LeanTween and TextMeshPro. I am using LeanTween.value() to change the positions of each letter of my TextMeshProGui. I wanted to add setEase(LeanTweenType.setEaseOutCubic) or something. And for some reason this doesn´t change the ease type. Any idea why? My exact code looks like this:

    Code (CSharp):
    1. LeanTween.value(gameObject, 0, 0.3f, animTime*5)
    2.             .setEaseOutCubic()
    3.             .setOnUpdate((float value) => { CODE THAT I THINK IS UNIMPORTANT RN})
    4.             .setOnComplete(() => { CODE THAT I THINK IS UNIMPORTANT RN });
    Hope you can help. Have a nice day! Max
     
  35. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    Does using setEase() work?
     
  36. Lagonas

    Lagonas

    Joined:
    Jul 13, 2017
    Posts:
    2
    Back then it did not. I somehow managed to make it work, without really knowing, what the problem was. My guess is, that the code I deemed unimportant, moved my object by constantly adding the value. Therefore the setEase() couldn´t really work. I found a workaround for that. Thanks though!
     
  37. OleksandrMartysh

    OleksandrMartysh

    Joined:
    Dec 13, 2015
    Posts:
    25
    Guys.. Did you see that? LeanTween asset was updated in Unity Asset Store!

    Version 2.51(current)
    Released: Dec 20, 2021
    2.51 - Fixed issues with 2022.1

    Although I still use Unity2020.3, so I don't know what "2022-problems" release logs are talking about.
     
    John-B, jRocket and yuliyF like this.
  38. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I like it and it is truly lean.
     
  39. sdb7

    sdb7

    Joined:
    Apr 8, 2013
    Posts:
    23
    Hi, is there any advice using it inside update method, performance wise, i posted my code below, i wonder is this efficient way to do inside update method?. thanks.

    Code (CSharp):
    1.  
    2. if(!LeanTween.isTweening(GunTraverseRoot.gameObject))
    3.                             GunTraverseRoot.gameObject.LeanRotateY(eulerTarget.y, .2f)
    4.                                 .setEaseInOutCubic();
    5.  
     
  40. Keaneo

    Keaneo

    Joined:
    Mar 7, 2015
    Posts:
    99
    If I start multiple tweens, what's the best way to check that ALL tweens are complete before running a final method?
    I could store the ID and poll to check - just wondering if there's a built-in approach?

    I see Sequences are great for serial tasks - something like that but in parallel?

    Thanks!

    EDIT: maybe I just use LeanTween.isTweening(gameObject)? It would be ideal to have an event of some kind.
     
    Last edited: May 3, 2022
  41. Nstdspace

    Nstdspace

    Joined:
    Feb 6, 2020
    Posts:
    26
    You could also just count the completed tweens until you reach total number of tweens. Something like this (untested) should suffice:

    Code (CSharp):
    1.  
    2. public class ParallelLean
    3. {
    4.     private int totalLeans;
    5.     private int leansCompleted;
    6.     private Action onComplete = () => { };
    7.  
    8.     public ParallelLean(params LTDescr[] leans)
    9.     {
    10.         totalLeans = leans.Length;
    11.         foreach (LTDescr lean in leans)
    12.         {
    13.             lean.setOnComplete(OnSingleLeanCompleted);
    14.         }
    15.     }
    16.  
    17.     private void OnSingleLeanCompleted()
    18.     {
    19.         leansCompleted++;
    20.         if (leansCompleted == totalLeans)
    21.         {
    22.             onComplete();
    23.         }
    24.     }
    25.  
    26.     public void SetOnCompleteAll(Action onComplete)
    27.     {
    28.         this.onComplete = onComplete;
    29.     }
    30. }
    31.  
    Usage would be like this:

    Code (CSharp):
    1. new ParallelLean(
    2.     object1.LeanMoveX(1, 1),
    3.     object2.LeanMoveY(2, 2)
    4. ).SetOnCompleteAll(() => Debug.Log("All tweens completed!"));
    This naive solution has some limitations, for example your original onComplete's would be overriden and you could pass LTDescr's into the constructor which already completed (well, one could use LTDescr-providing functions instead of the LTDescr themself then to clarify the intent to create new tweens).
     
    Keaneo likes this.
  42. unity_0DBB92696C21910327BA

    unity_0DBB92696C21910327BA

    Joined:
    Mar 31, 2022
    Posts:
    4
    I'm using LeanTween.Scale() to scale a gameobject from a scale of 0.1f to 1.0f. But I also want to make sure that the gameobject doesn't exceed the size of another gameobject. Is there any way I do that?
     
  43. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    You could use LeanTween.SetOnUpdate to perform your size check and cancel the tween if its bigger.
     
  44. farahsibtain

    farahsibtain

    Joined:
    Mar 15, 2022
    Posts:
    1
    Thanks. This is exactly what I want
     
  45. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    Catching up for a moment here — it looks like the original dev is (mostly) gone, but there's a fork by @Johannski now?

    I just ran into a problem with the main asset (LeanTween 2.51) involving Unity's reload settings. In the editor, if you go to Project Settings -> Editor -> Enter Play Mode Settings, you can untick Reload Domain and Reload Scene to allow Unity to enter play mode more quickly. This comes with some downsides however, and I noticed that LeanTween breaks when I do this. It works for the first iteration, but after I enter and then exit play mode once, the ~LeanTween object never appears again.

    Is this problem still present in the fork?

    I already have Surge and DOTween in my project, but switching these old tween to a new asset is not the biggest priority, so I'd like to leave them if I can. The problem could be something involving a static reference to a singleton instance; I had similar problems in my own code when I first unticked those two boxes.
     
    Genebris likes this.
  46. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Yep, that is fixed in the fork. The other change of the fork is, that everything is bundled in an assembly file and can be used with Unity Package Manager now. :)

    See also:
     
    Genebris likes this.
  47. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    Ah, you're right! This is working for me now. Thanks for updating it.
     
  48. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Hello,
    How to use LeanTween.delayedCall when game is paused (Time.timeScale = 0f)?
    My code
    Code (CSharp):
    1.  
    2. delay = LeanTween.delayedCall(0.5f, () =>
    3.  {
    4.        TooltipManager.Instance.Show(content.GetLocalizedString());
    5.  });
     
  49. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    Have you tried setIgnoreTimeScale?
     
    Only4gamers likes this.
  50. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    No. How to do this?