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

    CosmicGiant

    Joined:
    Jul 22, 2014
    Posts:
    23
    NVM! I managed to find a very good solution, again thx to your API!

    I've created a bool flag on the statemachine telling it that it's locked on current state, and refactored it so that state-changes happen on update, with kind of queue that saves the next state requested until the SM is unlocked and updates.

    Then, on the state I was using for experimentation, I have used another bool flag to know when all objects have started tweening (it's a loop in a coroutine that spawns and starts tweening them) and .setOnStart() to register each of the (now) ongoing tweening objects on a list... Then, used .setOnComplete() and .setOnCompleteParam() to later retrieve references to the same objects, remove from list, check if all have already started tweening (using previous flag, that is set to true at end of the coroutine), and if list is empty... If both "all-started" flag and empty-list check are evaluated true, I know I'm done with the tweenings, and set the SM's lock to false (was set to true inside the state, just before starting the coroutine, btw), which allows the SM to move to next state (requested somewhere earlier)... I think it's a very elegant solution (considering I'm a game-dev noob), and once again it's all thx to you!

    Your LeanTween is awesome! And by extension, you, it's creator, is even more awesome! :)
     
    dentedpixel likes this.
  2. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Muspell,

    There is no way to cache off an old version of the tween after it has completed. The engine itself recycles old tween objects, so there is no need to dispose of it. I would suggest putting the tweening code in one method, and then on clicking the button just recreating the tween each time. It's pretty efficient code, so it shouldn't be a lot of overhead. I hope that makes sense! Oh, and thanks I am glad you are liking the engine :)
     
  3. graviton

    graviton

    Joined:
    Jan 11, 2013
    Posts:
    75
    @dentedpixel

    So, I was triggering Tweens with a button press, anyway I tapped the button as fast as I could , and Unity crashed. Is it because I triggered too many Tweens, is there a limit to the number of Tweens I can have running?
     
  4. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    There are a limited number of tweens but the default is set very high (and you can change that default with LeanTween.init() ), it also shouldn't crash when you reach that limit but just print out an error to the console.

    You can use the LeanTween.isTweening method to check if you should fire off another tween or not on the button press. This should keep it from being overloaded...
     
    graviton likes this.
  5. Legi

    Legi

    Joined:
    Jul 25, 2013
    Posts:
    20
    Hi,

    i've been using LeanTween to fade in/out my tooltips.
    I'm using the following method to adjust the alpha of a CanvasGroup:
    Code (CSharp):
    1. void AdjustGroupAlpha(float value) {
    2.     group.alpha = value;
    3.     if (group.alpha == 0) {
    4.         background.gameObject.SetActive(showTooltip);
    5.     }
    6. }
    The reason for the SetActive call was to deactivate the tooltip just AFTER its alpha hits 0, and activate it just BEFORE its alpha gets changed from 0.
    Here's how I use LeanTween:
    Code (CSharp):
    1. LeanTween.value(gameObject, AdjustGroupAlpha, group.alpha, 1f, tweenDuration).setDelay(delayFadeIn);

    With version 2.4 the behaviour changed in that LeanTween no longer called the my method with a value of 0 when animating from 0 to 1. Therefore the if statement now is always false.
    It's an easy fix on my end, but I wonder if that was intentional with all the changes you've made in the latest release. :)
     
  6. pat68

    pat68

    Joined:
    Dec 15, 2013
    Posts:
    34
    Hi,
    today I've updated from 2.33 to 2.40.
    I am using LeanTween.moveY to move sprite game objects.
    After the update, nothing is moved and there were no changes from my side.

    This is what I am using:
    Code (CSharp):
    1.  
    2. lt1 = LeanTween.moveY(gameObject, gameObject.transform.position.y - 15.0f, durationFall).setEase(LeanTweenType.easeInQuad).setDestroyOnComplete(false).setOnComplete(OnAnimationComplete);
    3. lt2 = LeanTween.rotateAround(gameObject, axis, 360.0f, durationRotation).setRepeat(-1);
    4.  
    Any ideas?

    Greetings
    Pat

    Update
    I am using this in combination with LeanTween.rotateAround. If I delete rotateAround, the move is working. If I have both, only rotate around is working.
     
    Last edited: Oct 26, 2016
  7. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    Why do you use GameObject in operations: move/rotate/..? if needs only Transform
     
  8. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Pat,
    I have not been able to reproduce this problem. I pushed an example scene into my github that tries to recreate your issue, but it is tweening the sprite just fine. Maybe there is something else to your example that was causing it to fail?
     
  9. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I just wanted it to always be consistent, so you don't have to really think about it from one tweening method to the next. I can see the argument for using specific object types though depending on the type of animation... but that was my thinking behind it.
     
  10. dentedpixel

    dentedpixel

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

    Yeah I can see how that might have changed from the reworking. Sorry about that! I think you might want to change your code to adjust to how it works now, as in general I don't think it can be a guaranteed thing that you will get a 0f value, based on the tweening model.
     
  11. Legi

    Legi

    Joined:
    Jul 25, 2013
    Posts:
    20
    Good to know! The problem I had was easy to fix. I'll keep that in mind when using LT in other cases :)

    Thanks for the fast response, great Asset! :)
     
  12. pat68

    pat68

    Joined:
    Dec 15, 2013
    Posts:
    34
    Here is a stripped example project which reproduces the issue:
    https://1drv.ms/u/s!AnaggnXTpDAJlfxwTXi6u65K8GdiEQ

    If "LeanTween.rotateAround" is commented out, the moveY tween works.

    What is the exact link to your github example? I can't find this in the existing content.

    Greetings
    Pat
     
  13. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Pat,
    I was able to reproduce your problem once I added in the rotateAround piece in. Thanks for letting me know! I realized something I added in to simplify things introduced this bug. I have fixed it in the latest on github, the link is here: https://github.com/dentedpixel/LeanTween (my test scene is in LeanTween/Testing/Testing240.scene )
     
  14. pat68

    pat68

    Joined:
    Dec 15, 2013
    Posts:
    34
    Hi,
    thx for the fast response - now it works again.
    I am glad to help as this asset is for free and bug reporting is the least I can do! :)

    Greetings
    Pat
     
    dentedpixel likes this.
  15. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    Hi it `s a great tool on the vids but i just downloaded lean tween from Asset store and there is no "other" field in the create pannel nor anywhere else no sign of lean tween thing, exept Help popout:/
    There are two tuts on your channel i couldnt follow for that reason . Are the vids outdated?
    If so where i can find new upo to date tutorial vids?
    Thanks.
     
  16. jonc113

    jonc113

    Joined:
    Mar 10, 2013
    Posts:
    22
    Leantween.value, using a vector2, is no longer working.

    Hey Russell,
    been using Leantween for years. Love it, but:
    Just tried to upgrade from version 2.3.2 and my vector2's aren't changing.
    My code is:
    LeanTween.value(I.Mask, maskOrgSize, maskOrgSize * 2.22f, 1).setOnUpdate((Vector2 val)=>{ maskRT.sizeDelta = val ; }) ;
    the val's are all 0,0
    Reverting to 2.3.2 fixed the problem without any coding changes
     
  17. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Musolo,
    Unfortunately those videos are referring to the LeanTween Editor https://www.assetstore.unity3d.com/en/#!/content/9455, which is a paid asset (but it's what helps fund my further LeanTween development so consider giving it a purchase). I am glad you are liking the free asset though :)
     
  18. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Jon,
    Thanks for the heads up! I feel pretty bad for missing this pretty bad bug :-/ (I wrote a unit test for it so it shouldn't break in the future). Someone else actually mentioned this as well, and I have had the fix up on github for a couple of days: https://github.com/dentedpixel/LeanTween . I hope to submit a fixed version to the Asset Store tomorrow, so everyone will get the fix.
     
  19. Tuitive

    Tuitive

    Joined:
    Mar 25, 2013
    Posts:
    36
    No idea if this has been mentioned already, but with LeanTween Editor "control2" controls "node1" and "control1" controls "node2" and so on with as many nodes as I add. It's still usable, just confusing. I'd love to see "control1" control "node1", etc...
     
  20. Tuitive

    Tuitive

    Joined:
    Mar 25, 2013
    Posts:
    36
    I have a camera path that works great going from point A to point B, like this:
    LeanTween.move(player.gameObject,path1.vec3,2f).setOrientToPath(true);

    But I then want to call another method that backs it out from point B back to point A, but this doesn't keep the camera oriented to the path (even though it's told to):
    LeanTween.move(player.gameObject,path1.vec3,2f).setOrientToPath(true).setDirection(-1);

    ...and while this stays oriented to the path, it turns the camera around to face where it's going (I want it to back out, not turn around and go forward)
    LeanTween.move(player.gameObject,path1.vec3,2f).setDirection(-1).setOrientToPath(true);

    Any suggestions?
     
  21. kanda76

    kanda76

    Joined:
    Sep 4, 2013
    Posts:
    24
    Hello Russell,

    Your LT library is awesome. I use it for all my personal projects as well as professional ones. However i miss an important feature that can be found in another tweening system: moving a gameobject by moving the rigidbody instead of its transform. It would greatly help to move dynamic physics entities on low frame rate computers. That would be nice if you can add a Leantween.MoveRigidBody and LeanTween.RotateRigidBody, it would make Lean Tween the perfect lib in any situations. Thanks and keep up the good work!
     
  22. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Tuitive,
    Unfortunately the best solution at the moment is to embed the transform you are moving in parent transform. Then move the parent transform (with LeanTween.move( vector[] ) and orient the child transform in the opposite direction. I have been meaning to find a LeanTween api solution, but as it stands that is the best way to do it.
     
    Tuitive likes this.
  23. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks Kanda!
    I have heard people have had good luck hooking together a transform that they move with LeanTween with another that has a rigidbody attached by using a joint. I haven't had a chance to test it it out myself yet, but yeah I would like to get better rigid body support, or maybe provide some examples of how to joint bodies together with a tween...
     
    kanda76 likes this.
  24. MatthewHarmon

    MatthewHarmon

    Joined:
    Mar 5, 2015
    Posts:
    24
    Great package! Would really like direct support for TextMeshPro but because LT is compiled in the Plugins folder, I can't reference up to other namespaces. Any thoughts on a clean way for me to add support? Any reason I can't move LT out of Plugins?

    Also, I saw a mention of "custom properties" in a thread somewhere. Does this exist? If so, I assume the Editor does not support it?

    Thanks much... nice job on this.
     
  25. kanda76

    kanda76

    Joined:
    Sep 4, 2013
    Posts:
    24
    Thanks Russell. Looking forward to such a support. The advantage of Rigidbody.MovePosition is that it could be updated several times during a frame in FixedUpdate to avoid missing collision between thin colliders at low frame rates. As far as i remember iTween is supporting this automaticall if it detects a rigidbody on a gameobject that you requested to move. In my opinion it should'nt be automatically done, simply make a special LeanTween.MoveByPhysics function that will be updated in FixedUpdate (and same for Rigidbody.moveRotation) and tit will be perfect :)

    Anyway, thanks again your awesome plugin.
     
  26. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks Matthew!
    I put it into the Plugins folder so that you can access it with either UnityScript or C# in the same way. But I am not really sure how many people still use UnityScript, but I think it's still a sizable amount for it to matter.

    I am not sure what you mean about custom properties, you can tween just about any value with LeanTween.value maybe that's what you meant? Let me know how I could help in the integration.

    I hope that helps, I have heard good things about TextMeshPro!
     
  27. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    @dentedpixel It seems 2.4.0 broke using LeanTween.value with .setOnUpdate(Vector3 value), in my tests value keeps Vector3.zero.

    Example:

    Code (CSharp):
    1. LeanTween.value(this.gameObject, Vector3.one, Vector3.left, 1f).setOnUpdate((Vector3 value) => {
    2.             Debug.Log(value);  
    3.         });
     
    Last edited: Nov 7, 2016
  28. viame

    viame

    Joined:
    Jan 17, 2013
    Posts:
    7
    Hi.
    I got error after update latest version.

    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    csSplash.Destination () (at Assets/Scripts/csSplash.cs:175)[My Method]
    LTDescr.callOnCompletes () (at Assets/Plugins/LeanTween/LTDescr.cs:918)
    LeanTween.update () (at Assets/Plugins/LeanTween/LeanTween.cs:389)
    LeanTween.Update () (at Assets/Plugins/LeanTween/LeanTween.cs:328)

    This occur when scene is changed.
     
  29. viame

    viame

    Joined:
    Jan 17, 2013
    Posts:
    7
    setOnComplete method is called after scene is loaded.
    Can you fix it?
     
  30. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yup :-( I have it fixed on github, and I pushed a fix to the Asset Store over a week ago, but they are being really slow with their turnaround time.
     
    silentneedle likes this.
  31. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Viame,
    This issue is fixed on github as well, I am still waiting for the update to go through on the Asset Store :(
     
    silentneedle likes this.
  32. MatthewHarmon

    MatthewHarmon

    Joined:
    Mar 5, 2015
    Posts:
    24
    Ah, gotchya. Well, my challenge is to add support for TextMeshPro to the LeanTween Editor so my artists can easily animate UI elements. But since I'd need to have LeanTween become aware of TextMeshPro, I'm not sure this is going to be easy without moving LT out of the Plugins folder - unless you know a clever way around this.

    And yes, TextMeshPro is a really nice package. I'd venture to say that most pro-level Unity projects use it (assuming they have discovered it!) Very clever shader technique that works well even on older/slower devices. You should check it out.
     
  33. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    In file Assets/LeanTweenEditor/LTVisualShared.cs need add
    #if UNITY_EDITOR
    Undo....
    #endif
    for all Undo-s because you have an errors(such as:
    Assets/LeanTweenEditor/LTVisualShared.cs(328,33): error CS0103: The name `Undo' does not exist in the current context
    ) when building on Andoid platfom
     
  34. Vortavasail

    Vortavasail

    Joined:
    Apr 22, 2016
    Posts:
    44
    is there a way to attach a tween path to a game object ? what I'm trying to do it make a sword go into a sheath.
     
  35. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    Code (CSharp):
    1. var from = new Vector2(0, 0);
    2.             var to = new Vector2(256, 96);
    3.             LeanTween.value(gameObject, from, to, 0.1f).setOnUpdate((Vector2 value) =>
    4.             {
    5.                 Debug.Log("value=" + value);
    6.             }).setEase(LeanTweenType.easeInOutQuart);
    It doen't work : value = 0,0
    If simple float:
    Code (CSharp):
    1. LeanTween.value(gameObject, x, 256, 0.1f).setOnUpdate((float value)
    - all Ok
     
  36. dentedpixel

    dentedpixel

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

    Are you sure you have the latest in the asset store? There was a problem with Vector3 and Vector2 callbacks, but I fixed it in the latest version. The sample you gave is working fine in the version I am using (also on github).
     
  37. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thank you! I implemented the conditional compiler fix and will push that update soon.
     
  38. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    Thanks, I updated a LearnTweenEditor to 0.941 and it's worked, all fine
     
    dentedpixel likes this.
  39. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    305
    Anybody has experienced this problem?

    Code (CSharp):
    1.  
    2. foreach (int morphIndex in morphArray) {
    3.     LeanTween.value(gameObject, 0.0f, 10.0f, 0.3f).setOnUpdate((float value) => {                        
    4.         this.meshRenderer.SetBlendShapeWeight(morphIndex, value);
    5.     })
    6. }
    7.  
    Im doing a tween for each of my blendshapes, the problem is that it is not copying the block variables, instead they are passed by reference and it results in all the tweens tweening whatever reference is in morphIndex which in this case is the last element of the array.

    So cant we create Tweens with a for loop?

    I appreciate any help
     
  40. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    Error in code, set: LeanTween.value(gameObject, morphIndex, 10.0f, 0.3f)
     
    larku and dentedpixel like this.
  41. HarryWor

    HarryWor

    Joined:
    Jan 4, 2014
    Posts:
    3
    Hi Dented pixel,

    Im really enjoying using leantween so far and have just purchased the leantween editor.
    However I have come across an issue using the movelocal (Bezier) tween type in the Visual Editor.

    I have the object I want to move and the lean tween path as children of a parent game object. If the parent game object position is set to 0, 0, 0 everything works correctly. However if i move the position of the parent game object, the object i want to move does not stick to the path, it is offset too far in the direction the parent was moved.

    If that doesn't make sense i will send screenshots.

    thanks very much!

    harry
     
  42. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Harry,
    That does make sense, that actually sounds like expected behavior for moveLocal, if you want it to track where it is in the world position you want to just use the move method... It can get a little confusing though, knowing when to use one versus the other.

    Glad you are liking it so far :)
     
  43. HarryWor

    HarryWor

    Joined:
    Jan 4, 2014
    Posts:
    3
    Ah ok, my only issue with the move method is if i were then animating the parent, the regular move bezier wouldn't update this each frame right??
     
  44. HarryWor

    HarryWor

    Joined:
    Jan 4, 2014
    Posts:
    3
    Hi its me again :D

    I'm having another issue now on building the project to iOS

    its giving me compiler errors

    Assets/LeanTween/LeanTweenDocumentationEditor.cs(3,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?


    Assets/LeanTweenEditor/LTVisualShared.cs(356,33): error CS0103: The name `Undo' does not exist in the current context

    Assets/LeanTweenEditor/Editor/LeanTweenPathEditor.cs(261,40): error CS0117: `DentedPixel.LTEditor.LTVisualShared' does not contain a definition for `change'

    any idea what these are about? I also tried adding the leantween editor to a new project stripped down to basics and still get the errors.

    Sorry i'm not a coder more of a playmaker user :rolleyes:

    Do you need me to send the scene or code?

    thanks very much again for your help

    harry
     
  45. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
    Hey, is there still an update pending for the AssetStore? Just got version 2.41 and it's broken a number of LeanTween.move() calls when passed a Vector3, it just moves to 0,0,0 for me.
     
  46. dentedpixel

    dentedpixel

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

    Sorry I have to push an update for that, you have to wrap the code in that class with this compiler directive: #if UNITY_EDITOR

    I am attaching the updated file here.
     

    Attached Files:

  47. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Benzino07,
    I wasn't aware of any new bugs like this. Are there any other details to the bug? I am able to get LeanTween.move to go to the correct place. I will keep testing though.
     
  48. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
    Hey, I just tested it more and it's setOnUpdate which is the problem, the Vector3 inside it is always (0,0,0). Try out the below code and it should show the issue.

    Code (CSharp):
    1. LeanTween.move(someObj, new Vector3(20, 20, 0), 5.0f)
    2.             .setEase(LeanTweenType.easeInOutQuad).setOnUpdate( (Vector3 newPosition) =>
    3.             {
    4.                 Debug.LogWarning("New Position: " + newPosition.ToString());
    5.             });
    Pretty sure it's the same issue mentioned above but this is with the latest asset store version.
     
    dentedpixel likes this.
  49. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks for bringing this to my attention Benzino07 ! It was a similar issue to the one above but required a different fix. I have the fix on the latest github: github.com/dentedpixel/LeanTween . I will be submitted an updated version to the store soon, but for the time being you can get it there.
     
    SimteractiveDev likes this.
  50. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    305
    Why error in code? What you posted here is incorrect. That would tween the morphIndex which is not correct, instead what Im doing is tweening the value of an specific morph.

    Im posting my question again to see if I get any help.