Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    dentedpixel likes this.
  2. heretique

    heretique

    Joined:
    Apr 3, 2013
    Posts:
    3
    Hi, if I start a series of tweens one after another with the same params are they guaranteed to finish in the same exact order?
     
  3. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Sorry I have fallen behind on this forum page lately! I somehow stopped getting email notifications that there were new posts :-/

    Thanks for everyone who helped fill in by answering other people's questions :)

    I'll try and get to any un-answered questions soon.
     
  4. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Sorry about that, I had to do some cleanup around the 2d sprite path solution. Is there any way you can just rotate your spline 180 degrees to get the same behavior? Or if you could provide an example of when it behaves in this inverted manner that would be helpful...

    It seems to be working fine in my tests, so I just don't want to have it not working for anyone who has already started using it in the wold manner.
     
  5. dttngan91

    dttngan91

    Joined:
    Nov 21, 2013
    Posts:
    80
    I observed an issue related to movelocal in LeanTween. Sometimes and randomly, it stop moving suddenly without any reason? Is there anyone see that?
     
  6. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I have not seen that myself. If you can find a test case that isolates the problem (or a project you can share), I would be happy to look into it, it could be a bug.
     
  7. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    New promo trailer for LeanTween



    Prepare yourself for a whole lot of clapping!
     
  8. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hey dentedpixel,

    IMO all action happens too fast in that trailer. I had to watch it 4 times to try and see what each part was showing.
     
  9. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks for the feedback Larku. Yeah I can definitely see that, I wanted every scene to be in time with the beats, but I think I may have to stretch some of them out over 2 beats. I also got some negative feedback about my attempt at music, but I think I will keep my clap based soundtrack :)
     
  10. yohami

    yohami

    Joined:
    Apr 19, 2009
    Posts:
    124
    Hi, is it working on Unity 5?
     
  11. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Yohami,
    Yes it works fine in Unity5.
     
  12. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Hi could you help explain how to pass a param when calling onComplete. Ive tried:

    Code (CSharp):
    1.  
    2. LeanTween....
    3. .setOnComplete( DoSomething )
    4. .setOnCompleteParam( 1 ); // or [ 1 ]
    5.  
    6. //also
    7.  
    8. LeanTween....
    9. .setOnComplete( DoSomething, 1 );
    10.  
    11. void DoSomething( int value ) {
    12. }
    13.  
    Thanks.

    Also the example in the docs for "setOnCompleteParam" reads: "LeanTween.moveX(gameObject, 5f, 2.0f ).setOnComplete( tweenFinished );" which is the same for "setOnComplete".
     
  13. Berserker44

    Berserker44

    Joined:
    Sep 1, 2013
    Posts:
    29
    Hi Dentedpixel!

    I am using your Leantween in infinite runner project and it is great! I am currently trying to use splines to control the Character's path. However I am having a hard time doing two things:

    • I need to have my character traverse multiple splines. however I need to use the "iter/update" method. how can I have the gameobject transition to the next spline when it completes the first spline? I used the Leantween command method, but I need for it to not complete based time/frames so I am using the Iter/update method.
    • When I have the character transition to the next spline there is a brief rotation hiccup. I believe because it's pretty much teleporting to the next spline. it there any way I can lerp or smooth the spline transition?
    I purchased the Leantween editor, however I don't see any functions for that.

    If I could get these functionality, this would help me out absurdly!
     
  14. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422

    I'm not sure how LeanTween expects this to be done, but one immediate way I see would be to just use a delegate like:

    Code (csharp):
    1. LeanTween....setOnComplete( delegate() {
    2.   //
    3.   // Do anything you like here.  For example:
    4.   //
    5.   SomeAwesomeMethod(1);
    6. });
     
  15. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Ahola,
    Larku's response will probably be your easiest. In the past I have also wrapped the int objects in another object like:

    Code (CSharp):
    1. LeanTween.delayedCall(0.05f, enterMiniGameStart).setOnCompleteParam( new object[]{""+5} );
    2.  
    3. void enterMiniGameStart( object val ){
    4.         object[] arr = (object [])val;
    5.         int lvl = int.Parse((string)arr[0]);
    6.         Debug.Log("level:"+lvl);
    7.     }
    I'll have to update that part of the documentation... thanks for the heads up.
     
  16. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Hey, thanks for the help.

    The problem with the first solution is that the value can be modified before the tween completes e.g

    Code (csharp):
    1.  
    2. int someInt = 1;
    3. LeanTween....setOnComplete( delegate() {
    4. SomeAwesomeMethod( someInt ); // someInt will now be 2 because it is updated below before the tween is complete but I would like to send it as 1.
    5. });
    6.  
    7. someInt = 2;
    8.  
    Previously in Flash/Javascript I have used TweenMax, would there be anyway to add the simple "params" functionality, e.g:
    Code (csharp):
    1.  
    2. TweenLite.to( clip, 1.0, {
    3.     x:100,
    4.     onComplete : myFunction,
    5.     onCompleteParams : [ "param1", 2.0 ]
    6. } );
    7.  
    8. function myFunction( string param1, float param2 ) {
    9. }
    10.  
    Thanks!
     
  17. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hey aholla,

    This should be very simple, you could just do:

    Code (csharp):
    1. int someInt = 2;
    2. .
    3. .
    4. .
    5. int copyOfSomeInt = someInt;
    6. LeanTween....setOnComplete( delegate() {
    7.   //
    8.   // Do anything you like here.  For example:
    9.   //
    10.   SomeAwesomeMethod(copyOfSomeInt);
    11. });
    12.  
    13. someInt=3;
     
  18. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    Hi i am using unity 5 and leantween is throwing some errors. Ages ago i was using it and it worked find then.
    LeanTweenNotWorkingInUnity5.jpg

    It says it supports unity 5 but it doesnt work on unity 5. I reverted back to 4.6.4 then i got no errors
     
    Last edited: Apr 12, 2015
  19. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I have made a new version of the LeanTween promo trailer, that slowed things down a bit, and got rid of my amateur soundtrack:

     
  20. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Wendy,
    That is strange, it should work fine with Unity 5. Are you sure you have the latest one from the Asset Store?

    I just double checked importing it into a fresh Unity5 project, without any issues. Maybe delete your current LeanTween.cs and download it again?

    I hope that helps,
    Russ
     
  21. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hey dentedpixel, that's heaps better :)

    The sound track is a lot better also!

    I did notice that at the end you have the Lean Tween logo dropping in time with the beat in the audio track, but it's not quite on the beat - I'm being really picky here and only pointing it out to you because I'm a pedantic ar$ehole :) Totally no offence intended.

    Keep up the great work!
     
  22. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    I used a fresh project and also downloaded it. It was the latest version of leantween. Unity 5 with errors on one side and Leantween asset store on the other side. Its all up to date aswell.
    LeanTweenNotWorkingInUnity5FreshScene.jpg
     
  23. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hmm weird - any chance your Unity is broken? UI is in the UnityEngine.UI namespace it should always be present unless something has broken in your install...

    Perhaps try reinstalling Unity.
     
  24. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Haha, thanks no I love getting things right, so nitpicky feedback is always welcome. I think I am going to stick with this version for the time being and fix it on the next update to the feature video. I appreciate the feedback though.
     
  25. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    This is really funny but it didnt work in Unity 5.0.0 but i notice another version so i downloaded Unity 5.0.1 and then i dont get errors but just warnings weird ha but i did notice some module errors in 5.0.0 and when i installed 5.0.1 they went away so maybe that was the cause.
    LeanTweenUnity5.0.1.jpg
     
  26. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Excellent, glad to hear it's working.
     
  27. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Hey Russ,

    No problems - being nitpicky is one of my finer traits :)
     
  28. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Great! Yeah those warning should go away with the update I just submitted to the Asset Store (but they are just annoying warnings and don't effect any functionality)
     
  29. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Robert,
    You can tween a light with the value method, here is an example:

    Code (CSharp):
    1. GameObject light = GameObject.Find("DirectionalLight");
    2.             LeanTween.value( gameObject, (float val)=>{
    3.                 Light lt = light.GetComponent<Light>();
    4.                 lt.intensity = val;
    5.             },  1f, 5f, 5f);
     
  30. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Or do it this way (a little cleaner)

    Code (CSharp):
    1. GameObject light = GameObject.Find("DirectionalLight");
    2.             LeanTween.value( gameObject, 1f, 5f, 5f).setOnUpdate( (float val)=>{
    3.                 Light lt = light.GetComponent<Light>();
    4.                 lt.intensity = val;
    5.             } );
     
  31. therobear

    therobear

    Joined:
    Sep 28, 2010
    Posts:
    22
    Hello!

    Thanks for the reply. I actually had it like the second example you provided, but it didnt seem to work. I have the script in a function that I call manually. Here is the function:

    Code (CSharp):
    1. void LightCall()
    2. {
    3.      foreach (Light bLight in lightGroup)
    4.      {
    5.           LeanTween.value(bLIght.gameObject, bLight.intensity, 0.0f, 1.5f)
    6.           .setEase(LeanTweenType.linear)
    7.           .setLoopPingPong()
    8.           .setRepeat(-1)
    9.           .setOnUpdate((float val)=>{bLight.intensity = val;)};
    10.      }
    11. }
     
  32. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Robert, I think your c# formattting is a little off, see the example code I provided below. I made a test scene with very similar code that is up on github: github.com/dentedpixel/LeanTween (go to the TestingPunch scene and press 'q' on the keyboard to see it in action)

    Code (CSharp):
    1.  LeanTween.value(lt.gameObject, lt.intensity, 0.0f, 1.5f)
    2.               .setEase(LeanTweenType.linear)
    3.               .setLoopPingPong()
    4.               .setRepeat(-1)
    5.               .setOnUpdate((float val)=>{
    6.                
    7.             lt.intensity = val;
    8.             });
     
  33. Nims

    Nims

    Joined:
    Nov 11, 2013
    Posts:
    86
    Hi again, still enjoying this library immensely.
    I do have a question:
    Is there a way to get the length of a bezier/spline path?
     
  34. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Nims!
    Thanks, I am glad the library hasn't worn on you too much :)

    Shoot, I can't believe I didn't include a good bezier path example with the library. I have now added one that also shows how to get the length of the bezier path. You can see it in scene "PathSplinesBezier" on github .

    It doesn't look as simple to calculate the length if you are using the splines implementation, but there really should be a method for that... let me know if you need that instead.
     
  35. Berserker44

    Berserker44

    Joined:
    Sep 1, 2013
    Posts:
    29
    Hello

    I asked a question ealier about using beziercurves and spline but never really got a answer. SInce then i've developed something promising but I running into performance issues

    I am making an infinite runner where I am pooling a series of LT Bezier curves and then having the player travel it when it reaches it. I am using leantween to create the curves and using this LT function to have the player travel it:

    Code (CSharp):
    1. LeanTween.move(Player,Path.vec3,Speed).setOrientToPath(true).setEase(LeanTweenType.linear).setOnComplete(SetEnd);
    Every time the player travels to the new path, there is a HUGE, crippling spike in my framerate. Could anyone help me identify the issue? what would be the best way to have the player travel to one Bezier curve to the other?
     

    Attached Files:

    • Test.PNG
      Test.PNG
      File size:
      190.8 KB
      Views:
      944
  36. dentedpixel

    dentedpixel

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

    Sorry I never was really able to answer your earlier question, I was having a hard time trying to figure out the exact system you were trying to setup. I am glad you are having luck with your own solution though.

    From looking at the performance graph it looks like the huge spike in framerate has to do with activating the gameobject probably around the pooling code that activates/deactivates things. Specifically it looks to be the activation code in Animator that really spikes the framerate. LeanTween itself doesn't mess with any of that stuff, but I think you might be able to not suffer that performance by not deactivating/activating the objects... Maybe you can just hide the off screen when you are not using them?

    I hope that helps,
    Russ
     
  37. Berserker44

    Berserker44

    Joined:
    Sep 1, 2013
    Posts:
    29
    Wow, Thanks for the reply DentedPixel!

    Yeah, in my object pool, I am deactivating the models with the LT Paths after the player finishes traveling it, then I am reactivating and placing them randomly when a player needs to travel. I never knew deactivating and activating numerous objects was so expensive. Ill try a few things to replace the whole deactivating and reactivating process.

    How expensive is disabling and enabling a mesh renderer?

    Also, your Tween is amazing! it's really fast and I now I am able to do things in my ios project that I couldn't before
     
  38. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks Berserk! I am glad it's working out well :)

    I wouldn't think disabling/re-enabling a mesh renderer would have much of a performance hit, but I haven't experimented with it myself, so it would be best to investigate after trying that technique.

    I would love to see your project once you have something to share.

    Cheers,
    Russ
     
  39. spotavi

    spotavi

    Joined:
    Aug 30, 2014
    Posts:
    31
    I have scene-main which has a panel which i want to slide in from top.
    I do that with the following code:

    LeanTween.moveLocalY (nguipanel.gameObject, 200, 1f);

    Works fine on first time the scene gets loaded. If i reload the scene-main again ( hitting main menu from another scene ). The abobe code stops working and i dont see the panel moving.

    Any idea what could be wrong ? Using Unity 5
     
  40. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Nothing that I can think of. Not to pass the responsibility off but I see you are using NGUI. Possibly NGUI is caching the value of when it leaves the scene, and that's why it starts in that place when you come back to the scene? It's hard to say, if you are able to reproduce the issue not using NGUI I would be happy to debug the situation.
     
  41. spotavi

    spotavi

    Joined:
    Aug 30, 2014
    Posts:
    31
    I am assuming it cant be caching because i call it on clicking of a button and the code should execute again ?
     
  42. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Hi, is there a way to modify the "power" of an ease, e.g. make "Elastic" more/less elastic and "Back" more/less back?

    Thanks.
     
  43. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Looking at the LeanTween code I doesn't look like these aspects are configurable, but there is nothing stopping you either amending the ease modifier code (they're single functions). Or creating your own ease function and slotting it in. The LeanTween code is rather simple to follow once you look into it.
     
  44. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yes, unfortunately there is no way to modify these values at the moment, it is something I have been meaning to get to though. If you have any time and want to take a shot at it yourself, the code is open source on github. Otherwise I will try and get to it this weekend, it shouldn't take too long...

    Also you can always pass an AnimationCurve type for the tween. That way you can modify the easing to your hearts content :)
     
  45. Deleted User

    Deleted User

    Guest

    LTSpline.place is not working as I expected. In the image below you can see that a ratio of 0.5 with LTSpline places the avatar at the 0.5 position based on points, while the LTBezierPath.place places the avatar at the 0.5 position based on curve length. Is there a way to get LTSpline to place based on curve length?

    LeanTween.jpg
     
  46. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi MooseMouse,
    Unfortunately that is a known bug with LTSpline, something I hope to fix soon. LTBezierPath should work as you expect, placing it in the exact middle even if there are some paths of greater length than others. So that might be a workaround for you at the moment.

    I'll let you know when this is fixed! Thanks,
    Russ
     
  47. Deleted User

    Deleted User

    Guest

    Thanks for the info. Please post when it is available. I am making paths at runtime, and they are much easier to do with splines since the spline paths go through the points :)
     
  48. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Anybody have experience compiling code into a DLL? I have been trying to make a DLL version of LeanTween but it seems to always strip out and not recognize any class that isn't a monobehaviour...

    Here is the command I am using:

    Code (CSharp):
    1. mcs -r:/Applications/Unity5.0.2/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll -r:/Applications/Unity5.0.2/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll -target:library -recurse:'*.cs'
     
  49. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
  50. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey MooseMouse,
    I have fixed up the code so that it much more accurately moves at a constant speed when using the Splines (independent of the spacing of the different points). This also means that your test for 0.5f ratio should be much more accurately in the center where you would expect. If you need greater accuracy there is a variable LTSpline.SUBDIVIDING_COUNT you can set to higher to achieve that. You can find the latest up on github .

    I hope that helps!
    Russ