Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

DOTween (HOTween v2), a Unity tween engine

Discussion in 'Assets and Asset Store' started by Demigiant, Aug 5, 2014.

  1. s1m0n1stv4n

    s1m0n1stv4n

    Joined:
    Sep 14, 2012
    Posts:
    16
    Hi @Izitmee ,

    I have a tricky question for you :)
    Let's say I have a path above a 2d side scroller terrain, across the whole length of the level.

    I'd like to know the position that is on the path and has a specific x coordinate i.e. the point on the curve that is exactly above a certain object.

    Is there any way to get such info about the path?
     
  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @sheng319 Grab this update, which allows you to add delayed calls inside a Sequence and using an overall ease:
    Code (csharp):
    1.  
    2. DOTween.Sequence()
    3.             .Append(DOVirtual.DelayedCall(0.2f, MyRepeatCallback).SetLoops(10))
    4.             .SetEase(Ease.InOutSine);
    @s1m0n1stv4n Ahoy! The only way for a path to have a specific coordinate is if one of his waypoints have that exact coordinate (otherwise, you know, floating points imprecision), so you would just need to check the waypoints (ah! tricky answer). If instead you want to know if a point of a path is "around" a certain coordinate, I'm afraid there is now way :/
     

    Attached Files:

  3. s1m0n1stv4n

    s1m0n1stv4n

    Joined:
    Sep 14, 2012
    Posts:
    16
    Well yeah, that's what I suspected, but never mind. Thanks for the lightning fast answer though! :)
     
  4. FuzzyBalls

    FuzzyBalls

    Joined:
    Jun 12, 2014
    Posts:
    47
    loving the DOPath feature! it's awesome, I have something that i'm wondering if it's possible..

    So is it possible to select which waypoint I start my path on?

    Say my path has 10 waypoints and I want to start my path on waypoint 6, is that possible with DOTWeen? I looked into GoToWaypoint (index) but that didn't do anything

    I was thinking about doing it where I'd just create a new path from my full path, but then setting the duration will never match up accurately :(

    any ideas?

    thanks
     
  5. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    May I suggest renaming DOBlendableMoveBy to just DOMoveBy to be consistent with other tweening libraries?
    It would be great to see DOScaleBy, DORotateBy, and DOResizeBy as well.
     
  6. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @FuzzyBalls GotoWaypoint ;)

    @mdrotar The "By" tells that it's forced to be relative (as if you used SetRelative), but the "Blendable" is even more important to distinguish blendable tweens, imho. Those are not simply "by" tweens: you can already animate everything "by" by using the aforementioned SetRelative :)
     
  7. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    @Izitmee Ah, I see. Thanks! I guess I was assuming it worked like other libraries where "By" tweens are always blendable.
     
  8. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @mdrotar Oh I actually thought blendable tweens was a new thing. What other libraries are you referring to? Also, mhmmm, thinking about it I could make all relative tweens blendable. Will ponder this more.
     
  9. FuzzyBalls

    FuzzyBalls

    Joined:
    Jun 12, 2014
    Posts:
    47
    hmm how do you use it exactly then? because I tried to do it with that and it didn't work properly maybe I was doing it wrong.

    Do you have a example?

    thanks
     
  10. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    It may be a new thing for Unity. But the open source game library libGDX has this tween (aka actions) library built in:
    https://github.com/libgdx/libgdx/tree/master/gdx/src/com/badlogic/gdx/scenes/scene2d/actions

    It implements "By" tweens as blendable and has some other great features as well.
     
  11. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    48
    That's a great job :)
     
  12. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @FuzzyBalls I just discovered a bug there, when using non-linear eases. In the meantime, if you are using a Linear ease, and you're calling GotoWaypoint immediately after the path creation, you will also need to call FinalizePath before calling GotoWaypont (I'm fixing that too).

    @mdrotar Interesting. I checked my code, and the system I used to make DOBlendableMoveBy should work with all relative paths, so I might try to add that later today, if I have the time.
     
    mdrotar likes this.
  13. ilovemypixels

    ilovemypixels

    Joined:
    Oct 16, 2012
    Posts:
    6
    Hi, I have a basic question.

    Before Unity 5 I had this:-

    topA.renderer.material.DOFade( 0f, 1f );
    rightA.renderer.material.DOFade( 0f, 1f );
    bottomA.renderer.material.DOFade( 0f, 1f );
    leftA.renderer.material.DOFade( 0f, 1f );

    These are being converted to

    topA.GetComponent<Renderer>().material.DOFade( 0f, 1f );
    rightA.GetComponent<Renderer>().material.DOFade( 0f, 1f );
    bottomA.GetComponent<Renderer>().material.DOFade( 0f, 1f );
    leftA.GetComponent<Renderer>().material.DOFade( 0f, 1f );

    Now it is saying there is no renderer attached to these gameobjects, they are ui elements with a rect transform, canvas renderer and button components.

    What can i do ?

    Thanks for your help
     
  14. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hi,

    That is weird. Either Unity 5 got really confused with the renderer you were using, or it seems your objects are not the same as before. What exactly are you trying to tween? The button? If so, you can do this:
    Code (csharp):
    1. myButton.GetComponent<Image>().DOFade( 0f, 1f );
     
  15. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    textmeshpro.jpg

    Good news for all the users that asked shortcuts for Text Mesh Pro. Mr @Stephan B is kindly sharing a copy with me that I can use for testing, so DOTween Text Mesh Pro shortcuts will arrive sometime within next week ;)

    A note. For now I will only do script shortcuts. DOTween Pro's Visual Animation Editor can only work with regular Unity elements. But I will try to see if I can find a workaround for that.
     
    gjf and BTStone like this.
  16. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,418
    Awesome! How long do we have to wait for Pro~~~~ ?

    (I'm feeling like a little child asking his parents: Are we there yet?)

    :D
     
  17. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    :D I don't know, I hope the Asset Store will approve it within the weekend? For first-time submissions they apparently take quite a long time, but after that the update process seems to have become much quicker.

    In the meantime, check your mail ;)
     
    BTStone likes this.
  18. BogdanH

    BogdanH

    Joined:
    Aug 1, 2014
    Posts:
    2
    Hi ,

    Quick question about paths, are they for transforms only ?

    Basically , i want something like rigidbody2d.DoLocalPath which ignores rotations.

    Is it possible to use the generic way with a path , and maybe an example as i can't figure out how to do it from the docs?
     
  19. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    UPDATE 1.0.401
    • NEW: Added DOBlendableRotateBy, DOBlendableLocalRotateBy and DOBlendableScaleBy shortcuts
    • BUGFIX: Fixed sequence.Complete(true) not completing nested tweens
    • BUGFIX: Fixed issues when calculating the completed loops of a tween in case the duration is very small
    • BUGFIX: Fixed path orientation not ending correctly with Linear open paths
    • BUGFIX: Fixed tween.GotoWaypoint throwing an error if called immediately after path creation

    @BogdanH Hi! DOLocalPath currently doesn't work with rigidBodies, nor there is a generic DOPath way (it's hidden because I need to implement a better API for it). I plan to add a DOPath for rigidbodies (since a rigidbody can't move locally with physics calls, so a DOLocalPath would be useless and would still need to use transform.DOLocalPath), but I was delayed by the blendable tweens feature I just implemented. Now I'll work on Text Mesh Pro shortcuts and then probably prioritize rigidbody.DOPath.
     
  20. exitsimulation

    exitsimulation

    Joined:
    Feb 10, 2014
    Posts:
    82
    Hey Izitmee,

    I just upgraded to the current DoTween version, thanks for this!
    Like I said above the error I described is no longer an issue for me as I managed to work around it with "sequence.kill()". However, out of curiosity, I wanted to know if the error still occurs with the current version when I remove this line and unfortunately it does. The empty sequences are not getting killed by the garbage collector. It might be a very specific case when it occurs but I still wanted to let you know (in case you want to fix it). :)
    So here it comes:
    I have a method that returns a sequence based on a few parameters specific to my app. In some case the method returns an empty sequence. In the method where I grab this sequence I decide what to do with the sequence based on if it is empty or not. Here I added the sequence.kill() which is essential right now (otherwise DOTween crashes after a while -> see comments):

    Code (CSharp):
    1.  public Sequence GetTweenSequence(SomeParameter someParameter) {
    2.  
    3.         var tweenSequence = DOTween.Sequence();
    4.  
    5.         [...]
    6.         other cases
    7.         [...]
    8.      
    9.         // Special case
    10.         if (someParameter == SomeParameter.SpecialCase) {
    11.      
    12.             tweenSequence.SetId("empty");
    13.         }
    14.      
    15.         return tweenSequence;
    16. }
    17.  
    18. public void StartSomeTweenSequence() {
    19.  
    20.         var sequence = GetTweenSequence(someParameter);
    21.  
    22.         if (sequence.id != "empty") {
    23.  
    24.             sequence.OnPlay(delegate { stuff.... });
    25.             sequence.AppendCallback(someCallback);
    26.             sequence.Play();
    27.  
    28.         // if I remove this the sequences add up and finally crash DoTween, when exceeding the tween limit
    29.         } else sequence.Kill();
    30.      
    31.  
    32. }
    This is not the case. The tweens keep on adding up under "PausedTweens" and "ActiveTweens" until DOTween crashes. :)

    cheers monogon
     
  21. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @monogon Thanks for getting back to me on this again! While trying to replicate your issue once more, I found another bug (which was related to your case, I presume), where DOTween crashed in case there were a lot of Sequences, and they were more than the number of Tweeners. This update fixes it. Could I ask you to see if it finally works on your project too, without calling sequence.Kill? :)
     

    Attached Files:

  22. exitsimulation

    exitsimulation

    Joined:
    Feb 10, 2014
    Posts:
    82
    Nope, it's still there!
    But I think I found out exactly what causes it:
    When dealing with empty sequence AND Autoplay turned off the sequences are ignored by the garbage collector. I set up a scene where this bug occurs. (Clicking on the screen adds a new sequence which is not collected by the garbage collector).
    https://dl.dropboxusercontent.com/u/15121356/DOTweenBugSetup.zip

    Edit: It may not even be a bug. When I receive the empty sequence I am not playing it as you can see in my demo project. After playing it, it gets collected as usual...
    Like I said it's a bit of a weird case and I know understand why it happens this way. :D
     
  23. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @monogon Ah! Now it's clearer, though that is an intended behaviour. An empty Sequence is not garbage collected until it starts playing, so users can create a Sequence and fill it during a timespan longer than a single frame. I mean, it's intended behaviour as long as it doesn't create errors. With the latest fix it shouldn't crash DOTween. Or it still does? :O

    (I'm asking out of laziness instead than testing your project, because it's pretty late here and I'm running to bed)
     
  24. exitsimulation

    exitsimulation

    Joined:
    Feb 10, 2014
    Posts:
    82
    You are right, just checked it and it is not crashing anymore! :) The tweens capacity just gets raised. Perfect.
    I'll leave the sequence.Kill() in there though as I clearly don't need these sequences.
     
  25. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @monogon Wonderful then :) And yes, using Kill is definitely recommended in your case.

    I'll release the update officially as soon as I'm done with a new feature: string tweens that work correctly with rich-text tags :)
     
  26. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    While working on Text Mesh Pro's implementation, I decided to add rich text support to string tweens (activated by default, with options to deactivate it) —and by the way, it will obviously work with all strings and DOText shortcuts, not only with Text Mesh Pro. It's been kind of hell to implement it as efficiently as possible, but I'm finally done :) Gonna release it later today or tomorrow, after I add a few more things I have in my todo list.

    dotween_richtexttween.gif
     
    Last edited: Mar 29, 2015
    exitsimulation and BTStone like this.
  27. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    134
    Hello,

    Love what you have done with the text tweens and the addition of rich text support.

    I was wondering if there's a way to use DOTween to animate a score counter. For my game, at the end of each level, there is an end level screen where it shows the final scores, but it currently just calculates and shows the score at an instant. What I would like to do is be able to show the number counting from 0 all the way up to the total score within a given time. My current solution is to use Mathf.Lerp, but it doesn't seem as efficient if DOTween is able to do this.
     
  28. OnePxl

    OnePxl

    Joined:
    Aug 6, 2012
    Posts:
    307
    Came across this a few weeks ago: http://www.reddit.com/r/Unity3D/comments/2z7ye3/wanted_to_share_textracking_for_unity_546_ui/
     
  29. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @CF Games Other than the method @OnePxl suggests, with DOTween you could do this:
    Code (csharp):
    1. // Assuming you have a Text that shows the score, called myScoreText,
    2. // and the score is stored in a variable called myScore,
    3. // this would increase the score to 1000 in 2 seconds and show it while tweening
    4. // (well formatted with thousands separators)
    5. DOTween.To(()=>myScore, x=>myScore = x, 1000, 2).OnUpdate(()=> myScoreText.text = myScore.ToString("N"));
     
  30. timothyallan

    timothyallan

    Joined:
    May 22, 2013
    Posts:
    72
     
    exitsimulation, Demigiant and BTStone like this.
  31. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    UPDATE v1.0.420
    • CHANGE: myText.DOText and generic string tweens SetOptions have a new API, to implement the new rich text and scrambling options
    • NEW: Added rich text support and additional scrambling options to string tweens
    • NEW: Implemented long and ulong tween support
    • BUGFIX: Fixed DOTween Utility Panel preferences not being applied correctly in some cases
    • BUGFIX: Fixed IsTweening returning true if called inside the OnComplete callback of the same target


    BEWARE THE API CHANGE for DOText and SetOptions for string tweens. I never make API changes lightly, but this was definitely worth it considering the new features.

    Now, about the Text Mesh Pro shortcuts, I need some advice...
    I'm done with them, and I'm considering if I should release them in DOTween Pro (which should be out any day now, because it's been a long time since I sent it for Asset Store approval) or in the free version. What do you think? This might seem a rhetoric question (free VS payed? free!), but it's not, and I count on your honest advice :)

    @timothyallan :D
     
    BTStone likes this.
  32. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,418
    Put TextMeshPro-Shortcuts in Pro. DOTween Free is awesome, but filling Pro with cool stuff like Plugin-Shortcuts the makes Pro way more attractive.
     
    OnePxl and Demigiant like this.
  33. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Advice taken and approved, thanks :)
     
  34. OnePxl

    OnePxl

    Joined:
    Aug 6, 2012
    Posts:
    307
    Very good advice; TextMesh Pro is not cheap, so if you can afford that, you can afford DOTween Pro.
     
    Demigiant likes this.
  35. tawsm

    tawsm

    Joined:
    Nov 12, 2013
    Posts:
    43
    Hi,
    i'm trying to move an arrow sprite along the local x axis (in order to rotate the arrow freely while it always points forward). It has a rect transform component. What happens is, it tweens the arrow only on the global x axis, not on the local one.. This is my code:
    Code (CSharp):
    1.         // Tweening
    2.         transform.DOLocalMoveX((transform.localPosition.x + ArrowTranslation), ArrowDuration, false)
    3.                     .SetLoops(-1, LoopType.Yoyo)
    4.                     .SetEase(ease:Ease.OutSine);
    This is the arrow in the inspector:
    MoveArrow.PNG

    I also tried to cast to rectTransform and use the anchoredPosition, but it always only translated in global x. What am i doing wrong?

    EDIT: Ok, i figured out a solution.
    Code (CSharp):
    1. public class TutorialArrow : MonoBehaviour {
    2.  
    3.     public float ArrowTranslation = 50.0f;
    4.     public float ArrowDuration = 1.0f;
    5.  
    6.     void Start() {
    7.         // Initialization
    8.         DOTween.Init(true, true, LogBehaviour.ErrorsOnly);
    9.         Vector3 pos = transform.localPosition;
    10.         Vector3 trans = Quaternion.Euler(transform.localRotation.eulerAngles) * new Vector3(ArrowTranslation, 0, 0);
    11.         Vector3 dest = pos + trans;
    12.  
    13.         // Tweening
    14.          transform.DOLocalMove(dest, ArrowDuration, false)
    15.                     .SetLoops(-1, LoopType.Yoyo)
    16.                     .SetEase(ease:Ease.OutSine);
    17.     }
    18. }
    19.  
     
    Last edited: Apr 2, 2015
  36. timothyallan

    timothyallan

    Joined:
    May 22, 2013
    Posts:
    72
    Yeah man, Pro for sure. I can't wait to throw money at you.
     
    gjf and Demigiant like this.
  37. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    402
    Hi,

    I just came across this asset and it looks good and I am looking forward to the pro version.

    I am using this with CoreGameKit to spawn game objects that have an animation.

    In case it helps anyone, I found that when I set a looped tween going in OnSpawned() it would interfere with subsequent wav generation unless I put a transform.DOKill(); into the OnDespawned() method.

    Hope pro is coming soon :)

    N
     
  38. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @tawsm DOLocalMoveX/Y/Z moves an object using localPosition instead than position, so what you had initially in mind would work only if you were rotating the arrow parent while using DOLocalMoveX on the arrow itself. In the future I plan to add a DOLocalAxisMove which will do what you want, but I have other things higher in my todo list for now.

    @timothyallan @OnePxl Thank you! :)

    @puzzlekings Hi, glad you like it. You definitely should call a tween Kill when despawning your object, since auto-kill is activated only when an object is destroyed, not just deactivated (and thus will otherwise continue playing within the spawning/despawning cycles of a pool system).
     
  39. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,805
    Hey DoTween is awesome but we recently upgraded to a newer version to get around Tweens not being created from OnComplete methods.. But now there is a new bug in the latest version 1.0.420:

    float _spin; // member variable is a float

    DOTween.To((() => _spin, x => _spin = x, 1.0f, 0.66f).SetEase (Ease.OutQuad);
    DOTween.Kill(this);

    Basically Kill(this) doesn't seem to do anything - the tween still exists and they accumuate.
    If I do KillAll() then it clears it...

    I rolled back to version 1.0.310 but the problem still seems to be there... :)
     
  40. Mr_Cad

    Mr_Cad

    Joined:
    Dec 7, 2013
    Posts:
    27
    Hi, may I know how can I pass the Tweener as a parameter in callback?
    Code (CSharp):
    1. myObject.transform.DOLocalMove(newPos, 0.6f).OnUpdate(()=>OnObjectMoveCallback());
    2.  
    3. private void OnObjectMoveCallback()
    4. {
    5. // I want to get its tweener here? How?
    6. }
     
  41. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @AndrewRH Hi! A DOTween.Kill parameter can be either a tween's target (automatically set when using shortcuts) or an ID (manually set via SetId). In case of a generic tween like yours, there is no automatically set target, so DOTween.Kill(this) will find nothing to kill.
    Code (csharp):
    1. // This would work instead
    2. transform.DOMoveX(2, 1);
    3. DOTween.Kill(transform);
    In your case, you should instead store your tween reference and kill it directly:
    Code (csharp):
    1. Tween t = DOTween.To((() => _spin, x => _spin = x, 1.0f, 0.66f).SetEase (Ease.OutQuad);
    2. t.Kill();

    @Mr_Cad Just store it as a reference and pass it like this (note how I interrupted the one-line chaining to allow for the reference to be stored, before adding the OnUpdate call):
    Code (csharp):
    1. Tweener tweener = myObject.transform.DOLocalMove(newPos, 0.6f);
    2. tweener.OnUpdate(()=>OnObjectMoveCallback(tweener));
    3.  
    4. private void OnObjectMoveCallback(Tweener t)
    5. {
    6.    // Got it
    7. }
     
    Mr_Cad likes this.
  42. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    DOTween Pro is OUT! But beware, since the approval took so long, I moved on in the meantime, so it's not compatible with the latest version of DOTween, only with the previous one that comes packaged with it. Tomorrow morning I'm pushing a new update (updates should not take more than 24h) and then it will be fully powerful and I will make a more decent announcement :)
     
    Meceka and OnePxl like this.
  43. calebfoster

    calebfoster

    Joined:
    May 24, 2013
    Posts:
    5
    Is is possible to control the easing on some of the functions like DoShake? I'm trying to get DoShake to work without the non linear easing.
     
  44. veboys

    veboys

    Joined:
    May 26, 2014
    Posts:
    4
    hi,Izitmee
    how to set the time between every tow points when i use the DOPath method?
     
  45. timothyallan

    timothyallan

    Joined:
    May 22, 2013
    Posts:
    72
    Congrats!! Snagged it just now :)
     
  46. xcube

    xcube

    Joined:
    Nov 27, 2011
    Posts:
    45
  47. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @calebfoster Sorry but shake is a special tween that doesn't support true easing.

    @veboys Hi! You can't set the time between waypoints, only the time for the whole path. Though check out @Baroni's Simple Waypoint System (which now implements DOTween), because if I'm correct it should have such an option.

    @timothyallan Thanks! :) Gonna PM you the latest version now, while waiting for the Asset Store to upload it!

    @xcube Hi! Glad you like it and thanks for buying the Pro :) Gonna PM you too with the latest version in a few minutes. That said, the Visual Animation Editor works only with default Unity elements (though thinking about it, I might be able to add coloring for 2D Toolkit ones - will try it now). The scripting shortcuts though should totally work. Did you run DOTween's Setup AFTER importing 2D Toolkit?
     
    BTStone likes this.
  48. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,418
    Yep, +1 on Tweening 2DToolkit-Colors :p
     
  49. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    If the thing I have in mind works, I might even be able to add visual editing for Text Mesh Pro ;)
     
    gjf and BTStone like this.
  50. xcube

    xcube

    Joined:
    Nov 27, 2011
    Posts:
    45
    Yes I installed DoTweenPro after 2DToolkit