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

    sirio21

    Joined:
    Mar 11, 2013
    Posts:
    114
    ops, again-i need to call (concatenate) some methods passed as string. ie

    scale (2, "next2");
    void scale(float scl, string nextmethod) { LeanTween.scale(gameObject,scl,0.5f).setOnComplete( nextmethod ); }
    void next2() { scale ( scl+1 , "next3" ); }
    void next3() { Debug.Log("The End"); }

    How can i cast " nextmethod " ?
     
  2. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Do not pass the nextMethod argument as a string but instead as a System.Action type and that should work.
     
  3. thebaddie

    thebaddie

    Joined:
    Feb 27, 2016
    Posts:
    7
    Hi

    I'm trying to do something very easy as wait for a tween to finish before continuing with the regular code flow but i'm unable to find a solution to this.

    I tried using coroutines but the best result i obtained was delaying the start of the tween.
    I also tried to check for tween id and istweening but it works only while i'm testing my game state in update function not if I call a function and wait for it to finish.

    Thanks for any help
     
  4. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422

    You can just do this:

    Code (csharp):
    1. LeanTween.move(gameObject, ......).setOnComplete( () =>
    2. {
    3.     //
    4.     // Put code here that needs to run when the tween finishes.
    5.     //
    6. });
     
    dentedpixel likes this.
  5. thebaddie

    thebaddie

    Joined:
    Feb 27, 2016
    Posts:
    7
    That's ok if I have to execute code directly relative to the tween, but in my case I'm going through other functions and I have to "pause" the whole code waiting for the tween.

    A simplified version of my code flow is
    Code (CSharp):
    1. void update ()  {
    2.     ...
    3.     if (state == GameState.Check) {
    4.         if (Check()) {
    5.             Do();
    6.             Continue()
    7.         }
    8.     }
    9.     ...
    10. }
    11.  
    12. bool Check() {
    13.     ...
    14.     return true;
    15.     ...
    16. }
    17.  
    18. void Do() {
    19.     ...
    20.     FuncContainingTween()
    21.     ...
    22. }
    23.  
    24. void FuncContainingTween() {
    25.     ...
    26.     LeanTween...
    27.     ...
    28. }
    29.  
    30. void Continue() {
    31.     //continue with regular flow
    32. }
    So I have to delay the execution of Continue() (and other code too) until the tween in FuncContainingTween ends
     
  6. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey the theBaddie,
    You should just cache off the id of the tween than in your continue method you can check if the tween is still animating, before continuing, similiar to this:
    Code (CSharp):
    1. int id = LeanTween.moveX(gameObject, 1f, 3f).id;
    2.  
    3.  
    4. // check if it is tweening
    5. if( LeanTween.isTweening( id ) ){
    6.    return true;
    7. }
    8. return false;
     
  7. azmundai

    azmundai

    Joined:
    Jun 21, 2010
    Posts:
    26
    ok .. i cant get this to do what i want.

    this is what I have

    Code (CSharp):
    1.  
    2.         Vector3 startPos = transform.position;
    3.         float dist = Vector3.Distance (startPos, endPos);
    4.  
    5.         Vector3 midPos1 =  Vector3.Lerp(startPos, endPos, (dist * 0.1f) / dist);
    6.         Vector3 midPos2 =  Vector3.Lerp(startPos, endPos, (dist * 0.9f) / dist);
    7.  
    8.         midPos1 += Vector3.up * 2;
    9.         midPos2 += Vector3.up * 2;
    10.      
    11.         LTBezierPath ltPath = new LTBezierPath( new Vector3[] { startPos, midPos1, midPos2, endPos } );
    12.      
    13.         LeanTween.move (gameObject, ltPath, throwTime);
    all I want is a rock throw animation. So, a lob style trajectory .. so I tried creating control points that I thought would make sense .. but it still tweens out pretty linearly.

    any idea what I am doing wrong?

    endPos is defined properly. it ends at the right spot .. its just he path is linear.
     
  8. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yeah, it's a bit weird but the first and last points do not correspond to actual points the path passes through, but is instead just in there to influence the direction of how the curve comes in and goes out.

    So if you do not care about that information you can duplicate the first and last controls like:

    new LTBezierPath( new Vector3[] { startPos, startPos, midPos1, midPos2, endPos, endPos } );

    I hope that helps!
    Russ
     
  9. jo_tapper1

    jo_tapper1

    Joined:
    Oct 22, 2015
    Posts:
    1
    Hi Russell, or anyone that can help... :)

    Could you point me in the right direction for the best way to chain paths together? My game dynamically creates a long path from sections created with the visual path editor. This works well but I can't find a way to move smoothly from one path to another.
    What I'm doing now is to use setOnComplete to get the next path section and then call LeanTween.move with that new section. The onComplete call happens at the right time, but with the move function, the GameObject does not move on the first frame (the next frame after move was called). This means there's always one frame where the game object doesn't move, when transitioning from one path to another, causing an ugly jitter.
    I guess the move function waits a frame before changing the position.

    For clarity...

    Frame 1) LeanTween.move (m_char.gameObject, m_worldPath [m_pathSection].m_path.vec3, m_sectionSpeed).setOrientToPath (true).setEase (LeanTweenType.linear).setOnComplete (PathComplete);

    Frame 2) m_char.gameObject does not move

    Frame 3) m_char.gameObject moves correctly along path

    Obviously, the last node of the previous path is at the same position as the first node of the next path.

    Any ideas for a better way to chain paths, or to get LeanTween.move to apply movement on the first frame after it's called?

    Cheers!
     
  10. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hmmm, it should start immediately on the next path given this setup, but because the path probably ends and begin's at the same place it probably pauses an extra frame on that point...

    I think the best way to avoid this hiccup would be to give the next path traversing a little "push" like:

    LTDescr d = LeanTween.move( gameObject, nextPath, moveTime);
    d.passed = Time.deltaTime; // this is the nudge we need

    I think that should work, let me know if it doesn't.

    Cheers,
    Russ
     
  11. moh05

    moh05

    Joined:
    Nov 26, 2015
    Posts:
    65
    Hello everyone,

    Hope all is well :)

    I am a developer in Kuwait and was wondering about whether your tool is "mobile -performance" friendly when it comes to tweening UI elements.

    Basically I have a canvas set to World Render mode and I need to to move/rotate/scale cards ( using z value too). Did anyone tried that?

    Thanks in advance for your support.

    Regards,

    Mohamad Hindi
     
  12. larku

    larku

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

    Absolutely - LeanTween is a very fast tweening engine. I use it heavily for my mobile games and have never had any performance issues.

    I also use it for tweening elements on world space canvases without issue.

    I highly recommend it.
     
    dentedpixel likes this.
  13. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    936
    Hi there! I'm attempting to tween the value of a RectTransform pivot. I've found the example for tweening a vector2. However, nothing happens when I enter play mode. This is the code as it is right now:

    Code (CSharp):
    1.             LeanTween.value (gameObject, thisRect.pivot, pivotBotmLeft, .5f);
    2.  
    Any thoughts?
     
  14. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Tweening using value only calculates the values but does not assign them to anything, you'll want to do something like this:

    Code (CSharp):
    1.  
    2. LeanTween.value (gameObject, thisRect.pivot, pivotBotmLeft, 0.5f).setOnUpdateVector2((Vector2 pos)=>
    3. {
    4.   //
    5.   // assign the value you want here for each update step.
    6.   //
    7.    thisRect.pivot = pos;
    8. });
    9.  
     
    dentedpixel and Kellyrayj like this.
  15. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    936
    perfect! Thank you
     
    larku likes this.
  16. lparker

    lparker

    Joined:
    Apr 8, 2013
    Posts:
    30
    Hey,

    This is a brilliant asset and it works really well with all that I throw at it.

    I seem to have came into an issue though when changing back to a previously loaded scene, I'll go through what happens.

    1) Initial load of the main menu of my game (All the menus fade in and out using tweening depending on the options selected.)

    2) Load a different scene.

    3) Go back to the previous scene and the menus don't tween in (They are set to fade in using the alphaCanvas).

    I first thought I'd missed something so I decided to try going back to the other scenes which also use tweening in some way or another and for some reason leantween didn't fire.

    So this is what else I've tried:

    - Cancelling all tweens before firing the menu tweening bits.
    - Unloading the previous scene that was used each time.

    Both of which have yielded the same results, I'm not to sure if it's my own coding, a unity issue or if it's a leantween issue.

    Many Thanks,
    Luke.
     
  17. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Luke, I am glad you are liking LeanTween :)

    About your issue, do you get any type of error message leading up to this? I am not sure what could be breaking it...

    LeanTween persists from scene to scene, but you may want to not have this behavior to try and fix this bug. On the offending scene can you add the code:

    LeanTween.reset();
    LeanTween.init();

    Of course it would be best to find the reason it breaks in the first place, but that could be tough to do. One thing to check is to make sure all of your tweens are attached to a gameObject of some sort (and not a permanent gameObject, that persists between scenes), for example:
    LeanTween.delayedCall( 1f, someMethod )
    // This doesn't have a gameObject attached, but this does:
    LeanTween.delayedCall( gameObject, 1f, someMethod )

    This way things clean up best between scene changes.

    I hope that helps!
    Russ
     
  18. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    269
    Hey, I've been using LeanTween rather extensively, given how awesome it is. I'm having a bit of trouble figuring out a solution to this problem though, I was wondering if someone could help. I'm trying to tween along a spline with a few points, but would like to ease in/out to each individual point rather than the entire spline. Is there a relatively easy way to accomplish this?
     
  19. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Is this a bezier spline? You would just have to break it up into every fourth item and tween it along there, like:

    Code (CSharp):
    1. Vector3[] arr; // your path
    2.  
    3. for(int i=0; i < arr.Length;){
    4.   Vector3[] subArr = new Vector3[]{ arr, arr[i+1], arr[i+2], arr[i+3]};
    5.   LeanTween.move( gameObject, subArr, 1f).setEase(LeanTweenType.easeInOutQuad);
    6.   i += 4;
    7. }
    I am glad you are liking LeanTween :)

    I hope that helps,
    Russ
     
  20. Osteel

    Osteel

    Joined:
    Jan 17, 2014
    Posts:
    59
    Hi DentedPixel,

    Thanks for the awesome asset, I've been using it for a bunch of things! Just a quick question. Is there an easy way to substitute the time parameter with speed?

    Here's a basic scenario example:

    The player is dragging a box along the x-axis clamped between points 0 and 100. At any time, they can release the box and then LeanTween will simply tween the box from it's currently x-position to 100. However, the obvious happens with the time parameter since the closer you release near 100, the slower it will move.

    I know in iTween you could just choose whether the variable was time or speed, but I haven't been able to figure out if such a thing exists for LT? If not, do you know of any way I could achieve it?

    Thank you! :)
     
  21. dentedpixel

    dentedpixel

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

    Unfortunately there is nothing like this in LeanTween (I have left it out to keep the library more simplified). You can get around it pretty easily though by doing the calculation yourself like:

    float distance = Vector3.Distance( gameObject.transform.position, toObject.transform.position);
    float arbitrarySpeedRatio = 0.25f;
    float time = distance * arbitrarySpeedRatio;
    LeanTween.move( gameObject, toObject.transform.position, time);

    I hope that helps!
    Russ
     
  22. Osteel

    Osteel

    Joined:
    Jan 17, 2014
    Posts:
    59
    Okay, no worries! Yeah, I figured the alternative would be to use some calculation, but just wanted to make sure.

    Thanks alot. :D
     
    dentedpixel likes this.
  23. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    741
    Since this has been out, can you do a new comparison in performance since all the updates, its been a long time since the comparison vs Itween and it may not even be true anymore that the code is 5x faster as per your blog post from a long time ago.
     
  24. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Last I checked (about 6 months ago), it still obliterated iTween, but it was neck and neck with DoTween (the new Hotween did a great job catching up). I really should do an updated post on it, but I am really more busy keeping the asset up and putting out new stuff. The title of this forum post would be hard to update though...
     
  25. GilbertoBitt

    GilbertoBitt

    Joined:
    May 27, 2013
    Posts:
    111
    i need some help @dentedpixel i'm trying to create dynamic and random points to create a infinity path to my player walk thought it.. but i'm having hard dificulty always getting erros like:

    Code (CSharp):
    1. LeanTween - When passing values for a vector path, they must be in sets of four: controlPoint1, controlPoint2, endPoint2, controlPoint2, controlPoint2...
    2. UnityEngine.Debug:LogError(Object)
    3. LeanTween:logError(String) (at Assets/Plugins/LeanTween.cs:2559)
    4. LTBezierPath:setPoints(Vector3[]) (at Assets/Plugins/LeanTween.cs:4623)
    5. GameManager:OnCompletePaths() (at Assets/GameManager.cs:41)
    6. GameManager:Update() (at Assets/GameManager.cs:32)
    7.  
    and some like this

    Code (CSharp):
    1. IndexOutOfRangeException: Array index is out of range.
    2. LTBezierPath.setPoints (UnityEngine.Vector3[] pts_) (at Assets/Plugins/LeanTween.cs:4633)
    3. GameManager.OnCompletePaths () (at Assets/GameManager.cs:41)
    4. GameManager.Update () (at Assets/GameManager.cs:32)

    anyway can u help me understand and achieve with tween what i want? thank's in advance.
     
    Last edited: Mar 23, 2016
  26. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    741
    I would greatly appreciate it if you could investigate performance between them as of late, as it is a big deciding factor for me and i don't know how to bench test these scripts fairly. It was just recently spoken about in discord chat that iTween has caught up recently but no one posted any bench mark results. If you do have better performance on latest versions verses others i'll most definately convert from iTween as I am noticing slow downs.
     
  27. dentedpixel

    dentedpixel

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

    Like the error said you have to pass groupings of four to the move method, they are all little bezier curves that need an start point, end point and two control points. Bezier curves are sort of complicated though, I think you would be better off with the moveSpline method http://dentedpixel.com/LeanTweenDocumentation/classes/LeanTween.html#method_LeanTween.moveSpline

    Just make sure to read the note about the path:
    A set of points that define the curve(s) ex: ControlStart,Pt1,Pt2,Pt3,.. ..ControlEnd
    Note: The first and last item just define the angle of the end points, they are not actually used in the spline path itself. If you do not care about the angle you can jus set the first two items and last two items as the same value.

    I hope that helps!
    Russ
     
  28. GilbertoBitt

    GilbertoBitt

    Joined:
    May 27, 2013
    Posts:
    111
    @dentedpixel i fix it! thank's but now my player is running odd on my game he don't have a fix speed sometimes he become faster and other times slowly! and this sometimes give the impression of "warp" "teleport" on the player and no walk/slide like i want can u help me? i try change the time but is complicate.. have a wait to instead of define time to end spline/path define speed of the player in the spline?

    and how i make more smooth path/splines? for the player don't do thinks like turnBack! and a smooth transition between the end and the start of the spline. look my code! and since i'm using sprite 2d character i don't want rotation my character on all axis..


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameManager : MonoBehaviour {
    5.  
    6.     public GameObject Player;
    7.     public Vector3 raidius;
    8.     public float timeOfRun;
    9.     bool isStarted = false;
    10.     Vector3 LastPointCreated;
    11.  
    12.     void Start() {
    13.         LastPointCreated = Player.transform.position;
    14.         MoveSpline();
    15.     }
    16.  
    17.     void MoveSpline() {
    18.      
    19.         LeanTween.moveSpline(gameObject, PointCreator(10), timeOfRun).setEase(LeanTweenType.easeInOutCirc).setOrientToPath(true).setOnComplete(MoveSpline).setIgnoreTimeScale(true);
    20.         //LastPointCreated = PointCreator();
    21.     }
    22.  
    23.     Vector3[] PointCreator(int howMany) {
    24.         Vector3[] tempV3 = new Vector3[howMany];
    25.         for (int i = 0; i < howMany; i++) {
    26.             tempV3[i] = new Vector3(Random.insideUnitSphere.x * raidius.y + Player.transform.position.y, 0, Random.insideUnitSphere.z * raidius.z + Player.transform.position.z);
    27.                 //Random.insideUnitCircle * raidius+ Player.transform.position;
    28.         }
    29.         tempV3[0] = LastPointCreated;
    30.         LastPointCreated = tempV3[tempV3.Length-1];
    31.         return tempV3;
    32.     }
    33.  
    34.     Vector3 PointCreator() {
    35.         Vector3 tempV3;
    36.         tempV3 = new Vector3(0, Random.Range(Player.transform.position.y, Player.transform.position.y + raidius.y), Random.Range(Player.transform.position.z, Player.transform.position.z + raidius.z));
    37.         return tempV3;
    38.     }
    39. }
    40.  
     
    Last edited: Mar 24, 2016
  29. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Nice! To have better 2d behavior you should make sure you set .setOrientToPath2d(true)

    I am not sure about the jumping behaviour you described. Do you have an example project you could share?
     
  30. GilbertoBitt

    GilbertoBitt

    Joined:
    May 27, 2013
    Posts:
    111
    @dentedpixel i want something similar to the infinity version of this game.
     
  31. TribeWolf

    TribeWolf

    Joined:
    May 3, 2012
    Posts:
    14
    @dentedpixel Thank you for this great Tweening engine!

    Currently i'm switching whole my project from iTween to LeanTween (it is much faster, much less overhead and spikes) but i found one small problem - your documentation is a bit... simple :)

    For example, you don't have any descriptions for methods like LeanTween.delayedCall , LeanTween.moveLocalX(Y/Z), in some scenarios you use Hashtable - it would be great to know for what and how to use it :) If you'll have some time, maybe you can make several small video-tutors (or just text) wich will tell first-time-people about some specific things.

    For example, i've never saw constructions like ".setOnComplete(()=>{Method();});" (but it is extremely usefull)
    Code (CSharp):
    1. // Alpha Out, and destroy
    2. LeanTween.alpha(dude, 0f, 0.6f).setDelay(9.2f + i*0.4f).setDestroyOnComplete(true).setOnComplete(
    3.     ()=>{
    4.         Destroy( rotator ); // destroying parent as well
    5.     }
    6. );  
    I'm not a true Programmer, but i am doing pretty well with C#....

    Anyway i'll understand everything i need by some time - it's more "Thank you" post :)


    Best Regards,
    Ilia Nikitin

    Skype: ilya.p.nikitin@gmail.com
    Facebook: https://www.facebook.com/ilya.nikitin.391
    Twitter: https://twitter.com/NikitinIlya
     
  32. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Oh no, thanks for letting me know about the hashtable stuff, I thought I had scrubbed every last reference of it from the documentation, but it appears not! I was actually thinking of doing a getting started tutorial series, so it's good to hear that it would be useful. I was thinking of one tailored to more newbies and others for more experienced devs. Let me know if you have any specific questions until then, I am glad LeanTween is helping you with performance :)
     
  33. TribeWolf

    TribeWolf

    Joined:
    May 3, 2012
    Posts:
    14
    Actually i don't know what to ask for now - questions are more about some usage scenarios. For example, i have an "Enemy" unit that flies there and back by path. If player is near enemy it will disturb Fly animation, attacks player and if player go away by any way Enemy continues to move on his way from the stop point.

    In iTween i use for this two methods - iTween.ValueTo and iTween.PutOnPath so it is easy to operate with them. In LeanTween i did'nt found the solution for now (but i guess only for now).

    And one small advice - in iTween if you want to use path (i use it heavily) for movement you can just use an array of transforms (you don't have to convert it to Vertex3 array). It saves some time in developing and much easier for newbies. It also has good method iTween.DrawPath with uses an array of path Transforms to draw a bezier line - really usefull and very simple.

    Code (CSharp):
    1. void OnDrawGizmos()
    2. {
    3.     iTween.DrawPath(movePath,Color.red);
    4. }
    Or you just need to explain a bit your path implementation. You have some LTSpline, LTBezierPath. How to fill it with data or something like that... You use line like this:

    Code (CSharp):
    1.     public Transform[] trans;
    2.  
    3.     LTSpline cr;
    4.     private GameObject avatar1;
    5.  
    6.     void OnEnable(){
    7.         // create the path
    8.         cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} );
    9.         // cr = new LTSpline( new Vector3[] {new Vector3(-1f,0f,0f), new Vector3(0f,0f,0f), new Vector3(4f,0f,0f), new Vector3(20f,0f,0f), new Vector3(30f,0f,0f)} );
    10.     }
    But how to fill it on fly by code? Not a manual input.

    And one more small thing - Why your path needs 4 points? Is it possible to make it iTween-like - 3 points? It is a bit unclear :-(

    But anyway, LeanTween is a great Tween Engine. Only have a small lack of documentation :)


    Best Regards,
    Ilia Nikitin

    Skype: ilya.p.nikitin@gmail.com
    Facebook: https://www.facebook.com/ilya.nikitin.391
    Twitter: https://twitter.com/NikitinIlya
     
  34. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Oh yeah, I could add a list of transforms option. I am curious is the point of passing transforms, that if the transforms position changes the path also automatically updates? That is one upside I could see of using transforms over Vector3s

    I agree though, my path documentation is pretty lacking. I think I might aim to just come up with more extensive demo scenes that explain all those points better (maybe accompanied by a tutorial)

    There is a LeanTween.value (for tweening any variable)
     
  35. TribeWolf

    TribeWolf

    Joined:
    May 3, 2012
    Posts:
    14
    I just didn't want to spend time to completely switch that enemy to LeanTween for now - i'll do it later :)

    If i understood you right about your curiosity - with iTween you can move path points on the fly while playing and it will instantly update path. Sometimes it is usefull in animations or just for testing purposes (finding the best path while you are in the game mode).
     
  36. impactit

    impactit

    Joined:
    Jan 28, 2015
    Posts:
    41
    Hey.
    In 5.4 i got this warring (just info)

    OnLevelWasLoaded was found on LeanTween
    This message has been deprecated and will be removed in a later version of Unity.
    Add a delegate to SceneManager.onSceneLoaded instead to get notifications after scene loading has completed

    btw. great asset !!
     
  37. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Awesome! Thanks for the heads up, I'll make sure to change that for the next version :)
     
    impactit likes this.
  38. bzAdam

    bzAdam

    Joined:
    Aug 4, 2015
    Posts:
    39
    Hi, is there a simple way to tween the alpha of a RectTransform (or UI element) and have the alpha applied to its children.

    Currently when I want to reduce the alpha of a Button for example, the text within the button stays opaque. the work around is to use a canvas group and tween the alpha of that but its not a nice workaround.

    Thanks.
     
  39. VladimirTa

    VladimirTa

    Joined:
    Jul 17, 2013
    Posts:
    40
    Hello.
    iTween have LookTo, but in LeanTween I didn't found that.
    How can I make my object look at other object with LeanTween?

    Thanks.
     
  40. dentedpixel

    dentedpixel

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

    Sorry there is no built in way to do this at the moment :-/. It is something I am planning on adding at some point though.
     
  41. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey bzAdam,
    That is sort of an annoying restriction, so I made it by default be recursive for all RectTransforms, check out the scene GeneralAdvancedTechniques at http://github.com/dentedpixel/LeanTween to see it in action.
     
  42. bzAdam

    bzAdam

    Joined:
    Aug 4, 2015
    Posts:
    39
    Hi is this a new feature?

    I can't seem to get it to work.

    Code (CSharp):
    1. [SerializeField]
    2. private RectTransform playBtn;
    3.  
    4. [...]
    5.  
    6. LeanTween.alpha( playBtn, 0.0f,  0.0f ).setRecursive( true );
    This sets the buttons alpha to 0 but the text child within it stays visible.

    [EDIT] AH i tried adding a textfield to your example and it doesnt fade out either. So it is the UI TextFields.
     
  43. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    It is a new feature, so you will have to grab the latest on github to see it in action. Make sure to use LeanTween.textAlpha for tweening alpha of the text (this is also recursive if you grab the latest on github).
     
  44. bzAdam

    bzAdam

    Joined:
    Aug 4, 2015
    Posts:
    39
    Ah, so if I have text inside/as a child of a button, and I was to tween the buttons alpha to 0 I have to tween the button and also create tween for the text within it?

    Could it be made so that if you use "SetRecursive" it tweens the text alpha too? Otherwise for each of my buttons I will have to create and manage 2 tweens.

    Thanks for the updates!
     
  45. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I can definitely see how that could be annoying (anytime you want to alpha a button you have to do two tweens). I made an update that should make that happen automatically if it is set to recurse.
     
    bzAdam likes this.
  46. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I hope nobody is still using the #LeanTween 1.0 methods (hashtable based). They have only been available if you add a precompiler definition for quite some time. But they are being officially removed in the next release. #SpringCleaning

    If you want to grab the latest before they got removed it would be this commit
     
  47. bzAdam

    bzAdam

    Joined:
    Aug 4, 2015
    Posts:
    39
    Hi, I've run into another issue with UI Text ;)

    If i try and tween the alpha of a RectTransform that is a Text item, i get an error.
    If i set the tween to the gameObject instead of the REct transform it works.

    Code (csharp):
    1.  
    2. public RectTransform textField;
    3. ...
    4. private void DoATween() {      
    5.             LeanTween.alpha( textField, 0, 0 ); // THIS CAUSES AN ERROR
    6. ...
    7.             LeanTween.alpha( textField.gameObject, 0, 0 ); // THIS WORKS
    8. }
    9.  
    The error is a null reference, its looking for a uiImage in the RectTransform.

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. LeanTween.update () (at Assets/Plugins/LeanTween.cs:676)
    4. LeanTween.Update () (at Assets/Plugins/LeanTween.cs:324)
    5.  
    I hope this helps and is there somewhere else I should post issues/bugs?

    [EDIT: Looking at the docs I guess I should be using "alphaText" instead of just alpha. Maybe with the changes you made the other day, "alphaText" could be depricated and just alpha used? Thanks]
     
    Last edited: Apr 27, 2016
  48. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks for the heads up! Actually the forum is the very best place to post bugs/concerns. I fixed that null reference exception.

    Yeah, I decided to alpha the text as well if you are alpha-ing a RectTransform object and it is set to recursive, so I might be able to deprecate alphaText now...
     
    bzAdam likes this.
  49. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    I've been noticing that my scene files were getting pretty bloated and that loading times were getting longer. I save a lot of LTSplines on objects in my scene, and they seem to be the problem. A dip into a text editor shows that these splines contain a "ptsAdj" Vector3 array that, in my case, contains around 130 values that seem legit, and then at least 1500 more elements all at (0, 0, 0)! (The pts array seems just fine, though.) Since I serialize several hundred LTSplines in my scene, it's no surprise that the scene files are swelling!

    It looks like the ptsAdj array is public, so I was able to trim the arrays myself, but it would be nice not to have to!
     
    Last edited: May 4, 2016
  50. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Marble!
    Thanks for letting me know, I have added the [System.NonSerialized] property above that variable to make sure it doesn't get serialized (since it doesn't need to as it will be generated every time). I have also made some improvements recently to how large LTSpline grows in the latest version on github so maybe grabbing the latest will help in general improvements as well.
     
    Marble likes this.