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

DOTween (HOTween v2), a Unity tween engine

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

  1. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    Ha, well that explains why I'm getting an error trying to create this extension method!:
    Code (CSharp):
    1. public static Tween DOTween(this Color color, Color colorTo, float duration) {
    2.     return DOTween.To( ()=> color, x=> color = x, colorTo, duration);
    3. }
    And why you don't have direct Vector3 (or Vector2) tweens. Darn value types!
    Could you accomplish this internally somehow, maybe with a list of Colors or Vectors that you manage?
    And / or using reflection to access the referenced color / vector maybe? This is a little too advanced for me!
     
  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Doug.McFarlane Yup, and there is really no way, not even internally nor with the dreaded Reflection.

    @meapps I've still not used the new Unity UI, but if you write me the generic code you use to tween colors I will make it into a shortcut ;)
     
  3. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    @Izitmee i will i got the Health bar blinking working with Fading and Restart the Tween in OnComplete.
     
  4. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    Awesome. Thank you, great time saving tool!

    I Donated 20 bucks as well :)

    Maf
     
    Last edited: Oct 23, 2014
  5. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @mattSydney weeeeh! Thank you very very much Matt!! :)
     
  6. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    YaVeTaL likes this.
  7. gpvd

    gpvd

    Joined:
    Nov 2, 2013
    Posts:
    78
    Hello Izitmee,

    Is it possible to use a rotation tweener on a Vector3 instead of a Transform? E.g. DOTween.RotateTo().
    (At this moment i use the transform shortcut on a 'dummy' transform and then copy the values to a Vector3 field. Thats somewhat cumbersome and in my case i have a lot of Vector3 fields + equal dummy transforms, thus having a lot of overhead.)
    Greetz,

    G
     
  8. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    I'm going to assume no, since a Vector3 is a value type, and DOTween only works or reference types. This is because DOTween needs a reference to the source property in order to update it during the tween's life.

    @Izitmee, would it be possible for you to add a feature to do a Vector3 tween (or Color) something like this:
    Code (CSharp):
    1. Vector3 start, end;
    2. DOTween(start, end, 2.0f)
    3.     .OnUpdate((Vector3 currentValue) => {
    4.         transform.position = currentValue;
    5.     });
    6.  
    Excuse my lack of Lambda knowledge! No idea if this is a valid lambda expression, it was just to illustrate.
    Is there a way to pass back the current value (managed by DOTween) in this way? That way DOTween doesn't need a direct reference to the original Vector3, it just uses a local Vector3 to use while tweening, and passes the current value to the OnUpdate() method for the user to do with it what he wants.
     
    Last edited: Oct 23, 2014
  9. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Doug.McFarlane You can already do that, using the generic methods :)
    Code (csharp):
    1. Vector3 start, end;
    2. DOTween.To(()=> start, x=> start = x, end, 2.0f)
    3.   .OnUpdate(()=> transform.position = start);
    @gpvd The generic To method can be used to achieve what you want, but consider that generic rotation tweens require a Quaternion target, so:
    Code (csharp):
    1. DOTween.To(()=> myQuaternion, x=> myQuaternion = x, endValue, duration);
     
  10. gpvd

    gpvd

    Joined:
    Nov 2, 2013
    Posts:
    78
    @Izitmee The reason i asked is because with the transform shortcut, boolean useShortest360Route can be set, which can also be convenient when rotating a vector.
     
  11. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @gpvd With the generic methods options like useShortest360Route are included via SetOptions (which shows different options based on the type of tweened value). Just remember that SetOptions is special and needs to be chained immediately after the creation tween and not after other settings are applied.
     
  12. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    I currently use generic methods - but do they only work with float types?

    I'm getting an error when I try Color and Vector3:
    Delegate 'DG.Tweening.Core.DOGetter<UnityEngine.RectOffset>' does not take one arguments'.

    Is there a special syntax I need to use? I could tween each Color (or Vector3) element separately, but then I'd have 4 tweens running for one color, and I'd have to marry them together each update somehow.

    Don't worry about it, as I have no immediate need for this, just trying to learn.
     
  13. gpvd

    gpvd

    Joined:
    Nov 2, 2013
    Posts:
    78
    @Izitmee Ok, tnx!
    Greetz,
    G
     
  14. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Doug.McFarlane Nono they work with every possible type I could think of. Can you show me the code you're using to create them so I can see what's wrong (sadly, given the nature of Unity's own objects — Vector, Color, Rect, etc — the error log when using the wrong type on a generic To is not helpful at all)?
     
  15. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    Hi

    Is it possible to combine a tween, e.g. to the object moves and rotates at the same time? I tried this method but it didn't work. It "looked" at the wrong place like last time.

    Code (CSharp):
    1. DOTween.Sequence()
    2.                     .Insert(0,player.transform.DOMove(objectToMoveTo.position,1,false))
    3.                     .Insert(0,player.transform.DOLookAt(objectToLookAt.position,1));
    4.  
    5.             }
    Thanks!
     
  16. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @mattSydney Yes you can, but no you cannot. Once you create a tween the animation is "locked", so the lookAt is actually working but with the original rotation before the move started. Let me think about how I could possibly allow a dynamic lookAt instead (so that the lookAt rotation is re-acquired every update) and I'll try to implement it.
     
    mattSydney likes this.
  17. Griffith

    Griffith

    Joined:
    Oct 19, 2011
    Posts:
    23
    Hi mate,

    Really impressed with the tween engine, any idea when we'll be able to invest in the pro version of Dotween?

    Thanks
     
  18. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    938
    Is there a reason why the "PlayBackwards" method is ignoring the delay of the Tweener?
     
  19. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    938
    And another question... The "PlayBackwards" method of the Sequence is not triggering the "OnComplete" callback for some reason. Any idea why?

    Thanks!
     
  20. DanTaylor

    DanTaylor

    Joined:
    Jul 6, 2013
    Posts:
    119
    Hey there - I love HOTween, and this looks like a substantial improvement.

    Quick Question:
    HOTween is integrated extensively into the app I am currently making...
    Is there an easy way to quickly switch the two?
    (E.g. Find and replace "HOT" with "DOT").

    I am guessing the answer is "no", but one can but dream!

    Keep up the great work!!!

    Cheers,
    Dan
     
  21. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Griffith Glad you like it :) Before releasing the Pro I have to complete the path editor and the path plugin, so I'd say another 3 weeks (but maybe more).

    @luispedrofonseca Delays are "extras" and not really part of the tween, so once they have elapsed they're not considered anymore (unless you call methods like Rewind with the optional includeDelay as TRUE). And about OnComplete, it's called when a tween completes only if moving forwards. If you want to know when a tween as fully played backwards you can use OnRewind.

    @DanTaylor Glad you like it too :) And sorry if I shatter the dream but no, no easy "replace HOT with DOT" way (though it didn't take me long to replace DOTween with HOTween in my game Goscurry — which obviously had tons of tweens). DOTween has a similar but substantially different API, much shorter to use and without strings.
     
  22. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    542
    Hey.

    I got a problem with the callback functions in DOTween where I don't exactly know how to solve it:

    Code (csharp):
    1.  
    2.   public void doAttack (BattleRoundConfrontation confrontation, TweenCallback callback)
    3.   {
    4.   Sequence animationSequence = DOTween.Sequence();
    5.  
    6.   animationSequence.Append(target.playDamageAnimation(confrontation));
    7.   animationSequence.AppendCallback(target.updateData); // NOTE: need to give over "confrontation" data somehow to callback function
    8.  
    9.   animationSequence.Append(aTweener);
    10.   animationSequence.OnComplete(callback);
    11.   }
    12.  
    13.   private void updateData() // NOTE: this would be great if here could be params
    14.   {
    15.       // TODO: need to update my data here! Best I can give some params with the callback
    16.   }
    17.  
    With HOTween it was possible to give custom params as an object for the TweenParams, which then were accessible in the callback function. It would be great to have something like that again or is it possible to do it in another way in DOTween?
     
    Last edited: Oct 25, 2014
  23. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    542
    Ok, the green box on in the documentation saved me :)

    Thanks!
     
  24. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    I saw your tweet but hadn't yet seen the forum post. Saint green box! I should've added that a while ago :)
     
  25. RichHurst

    RichHurst

    Joined:
    Jul 25, 2013
    Posts:
    30
    @Izitmee hey how's it going? Really enjoying the updates and improvements. I've got two questions / maybe suggestions...

    I know I can tween audio by using the generic way, but perhaps this would make a useful shortcut since it seems like there could be a common need for it?

    Secondly, is there anyway to detect when a tween is at it's desired end point on a bounce / elastic ease? Just so I'm clear about this I don't mean just when it's completed, so for instance if you tweened an x value from 0 to 100 with a bounce ease, it would hit 100 and then reduce again for the overshoot / amplitude, then returns to 100 again to complete. I know I could check for values, but this seems to change depending on the device / scenario etc. The reason I'm asking about this is because I would like for something to bounce in on the screen, I wish for it to appear to squish on the bounce and play a noise, I know I can achieve this through timing or various position checks, but I was wondering if the tween engine already knows these stages, or if it's easy to detect. If so, would it be possible to have a function like OnEndvalue?

    Hope that makes sense, I'm not meaning to add to your already expanding workload on this, but thought I'd mention it incase you think these are valid / worthwhile suggestions that are easy to implement.

    Thanks
     
  26. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hey @RichHurst! :) Crazy times here, whew!

    Suggestions are always welcome, but I'm afraid what you're asking is not doable. Eases are pure algorithms, and checking if a target has bounced over an end value with the elastic/back/bounce eases would imply a billions of checks that would massively slow down the engine. That's because the end value is perfectly reached by the end of the tween, but not WHILE tweening (with those eases). For example, if the end value is 2 and the elastic reach is 3, the target could move from 1.9 to 2.1 between one frame and the next, and to check if it "touched" 2 I would need to add formulas that let me know A) the current direction of the ease (is it bouncing forward or backward?) and B) if the difference between the previous state and the current one overlayed the end value. And maybe the tween is set to go so fast that the target actually "touched" the end value more than once since the previous frame. So, too much math for this case (considering it would need to be update each frame), baaaad for performance.
     
  27. RichHurst

    RichHurst

    Joined:
    Jul 25, 2013
    Posts:
    30
    @Izitmee yeah, completely makes sense... And thanks for taking the time to reply with why it's not a good idea!

    What are your thoughts about the audio fade shortcut? I know I can create my own, just thought it might make a good one to add to the already expanding list...
     
  28. Neophen

    Neophen

    Joined:
    May 28, 2014
    Posts:
    21
    Hey I wonder how would I tween a text.
    I have a text object it moves to position, scales ,(this is where I need help) Counts down to zero (extra credit if you tell me how to elastically scale it up and down a little while counting down) and at the same time it calls another tween to increment the main score Text on scene, scales to 0, calls a callback.

    Any help is greatly appreciated. Love your engine!!!!

    using unity 4.6 b20
    My code:
    Code (CSharp):
    1. public void addScore(int score, Vector3 position)
    2.         {
    3.  
    4.                 //GameObject TextGO = pS.InstantiateAPS ("ScoreText", position, Quaternion.Euler (Vector3.zero));//, GameCanvas.gameObject);
    5.                 GameObject TextGO = Instantiate(ScoreText, position, Quaternion.Euler (Vector3.zero)) as GameObject;
    6.                 TextGO.transform.parent = transform;
    7.  
    8.                 Text currentText = TextGO.GetComponent<Text> ();
    9.                 currentText.text =  score.ToString();
    10.  
    11.                 Sequence mySequence = DOTween.Sequence();
    12.                 // Add a movement tween at the beginning
    13.                 mySequence.Append(currentText.rectTransform.DOMove (finishRect.position, duration, snap).SetEase(DG.Tweening.Ease.OutElastic,Amplitude));
    14.                 mySequence.Append(currentText.rectTransform.DOScale(ScaleVector, ScaleDuration));
    15.                 //Insert here Count down the currentText.text to 0 while increasing the mainObjects.text to the starting value of score
    16.                 mySequence.Append(currentText.rectTransform.DOPunchScale(Vector3.zero, ScaleDuration, PunchVibrato, PunchElasticity));
    17.                 mySequence.OnComplete (()=>finishScore(TextGO));
    18.  
    19.         }
    Thank you for any help! :)
     
  29. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Neophen Answered your mail :)

    @RichHurst Wooops I got lost in explaining why the elastic check wasn't a good idea and forgot about the audio shortcut. I was actually thinking of adding audio shortcuts when Unity 5 comes out, since the audio system is completely revamped, but now I'm gonna add some for Unity 3/4 too :)
     
  30. RichHurst

    RichHurst

    Joined:
    Jul 25, 2013
    Posts:
    30
    @Izitmee Haha, yeah I figured that question may have been a bit distracting. Thats great, I think it will be handy and will be good for people who don't upgrade to Unity 5. I don't think I'll be able to port my current project to Unity 5 due to the way it uses cloth.

    Thanks
     
  31. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @RichHurst AudioSource.DOFade (tweens the volume) and DOPitch (tweens the pitch) shortcuts added :) I'm attaching it here instead than releasing it officially, so you can let me know if you think other audio shortcuts might be needed.
     

    Attached Files:

  32. RichHurst

    RichHurst

    Joined:
    Jul 25, 2013
    Posts:
    30
    @Izitmee Thats brilliant, thanks. Yeah it works perfectly for my needs, have only tested the DOFade at the moment but I will experiment with the pitch tween later / tomorrow.

    Personally I think these shortcuts would be enough, in fact I wasn't even expecting you to add the pitch but now that you have there are bits where a tweened pitch will be handy. Im sure some would ask for pan 3D / 2D, doppler and spread but I don't have the need for these yet (can't imagine needing it in my current project). I don't want to unnecessarily add more to your workload just for the sake of it...

    FYI... Also, I did have an idea how I could solve my earlier problem of the elastic / bounce / back using the percentage elapsed and an int to count the various stages... It seemed to work, but in the end resorted to back to just a timer as the sound synch didn't quite work on an iPhone... (could be something to do with a slight delay in playing sound on iphones etc).

    Thanks once again!
     
  33. gpvd

    gpvd

    Joined:
    Nov 2, 2013
    Posts:
    78
    Hello Izitmee,

    I've a question about the path plugin;

    Is it possible to make it available for Vector3 also?
    I really wouldn't tween the transform directly because the Vector3 to be tweened is added to a bunch of other Vectors before finally assigning it to a transform.

    Tnx in advance,

    Greetz,

    G
     
  34. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @gpvd Adding that to my todo list. It's actually already possible but with a complicated API: I'll see if I can make it more readable :)
     
  35. gpvd

    gpvd

    Joined:
    Nov 2, 2013
    Posts:
    78
    Ok,

    That's great, thanks!
     
  36. SantosR

    SantosR

    Joined:
    Dec 18, 2013
    Posts:
    27
    I'm unable to add a callback function to the OnComplete, I get this error:

    Error 6 Delegate `DG.Tweening.Core.TweenCallback' does not take `1' arguments


    Code (CSharp):
    1. imageSelf.DOColor(IN_COLOR, .4f).onComplete(TransitionCallback);
     
    bobmoff likes this.
  37. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @SantosR it's OnComplete, with the first O uppercase. If you write "onComplete" instead you're accessing the callback variable which works differently.
     
    SantosR likes this.
  38. leemin

    leemin

    Joined:
    Oct 29, 2014
    Posts:
    3
    I want to change the position and texture alpha of five gameobjects at the same time. The code like this :
    Code (CSharp):
    1.  mySequence.Append(cardList[i].transform.DOMoveX(((i - 2) * x), i * stepTime));
    2.             mySequence.Append(cardList[i].gameObject.GetComponent<UITexture>().alpha.To())
    I don't know how to use the DOTween to make the alpha change.
    Anyone can give me help. Thank you
     
  39. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    If you're using tk2d, you can set alpha via
    Code (CSharp):
    1. DOTween.ToAlpha (() => sprite.color, x => sprite.color = x, 0, 0.1f)
    2 Izitmee
    probably you have to create a FAQ, based on a common questions in this thread
     
  40. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Thanks for the reply YaVeTaL :) I indeed have a FAQ and basics examples on the website, but I suppose I should extend them. I'll see if I can work on it next week.
     
  41. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    Damned, i'm stupid: i didnt write down the solution last time, and now got in the same problem again :D:mad:

    So, when i'm writing either DOMoveY() or DOLocalMoveY(), i got a movement to global position.
    transform.DOMoveY (.5f, 0.15f); moves object to global coordinate (*.0.5,*), not currentPos.y+0.5.

    How should i do that in elegant way?
     
  42. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    And just another fast (i hope so) question:

    Code (CSharp):
    1. private Sequence slideSeq;
    2.  
    3.     public void Start()
    4.     {
    5.         slideSeq = DOTween.Sequence ();
    6.         slideSeq
    7.             .Append(transform.DOMoveY (transform.position.y + .3f, 0.3f))
    8.             .Insert(0f, DOTween.ToAlpha (() => textMesh.color, x => textMesh.color = x, 0, 0.3f))
    9.             .SetAutoKill(false).Pause();
    10.     }
    11.  
    12.     public void Show(string score)
    13.     {
    14.         textMesh.text = score;
    15.         slideSeq.Restart ();
    16.  
    17.         //DOTween.ToAlpha (() => textMesh.color, x => textMesh.color = x, 0, 0.3f);
    18.         //transform.DOMoveY (transform.position.y + .3f, 0.3f);
    19.     }
    What can be wrong with seq here? It works fine for those 2 tweens.
     
  43. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Aha, that happens :D
    If you want your move to use the endValue as a relative value (meaning it gets added to the target's starting value instead than be considered a "go there and that's it", just add the SetRelative option:
    Code (csharp):
    1. transform.DOMoveY (.5f, 0.15f).SetRelative();

    That seems alright to me. What is happening?
     
  44. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    SetRelative() now works, but what's the difference between DOMove() and DOLocalMove() ?

    Ah, sorry, was a bit sleepy and missed the question state :)
    Seq is not affecting the sprite at all, while tweens works fine. Sprite just appears and do nothing if to use the code as above. But if to uncomment tweens, it does the job: moves up and become invisible.
     
  45. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    DOMove tween a transform's position, while DOLocalMove tweens a transform's localPosition.

    About the Sequence not animating anything, the issue is probably that you're creating the Sequence at Start, while the working tween is created when you call Show. Consider that a Sequence takes the start value of their targets only when it actually starts (which happens later in your case because you pause it), so you're probably setting the textMesh to alpha 0 before it starts, then the tween goes from 0 to 0.
    If you want to "FIX" the start values of a Sequence/Tweener so that they're taken immediately, replace your Pause() with a Rewind() (that way the Sequence is immediately initialized).
    Code (CSharp):
    1. slideSeq = DOTween.Sequence ();
    2.         slideSeq
    3.             .Append(transform.DOMoveY (transform.position.y + .3f, 0.3f))
    4.             .Insert(0f, DOTween.ToAlpha (() => textMesh.color, x => textMesh.color = x, 0, 0.3f))
    5.             .SetAutoKill(false).Rewind();
     
  46. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    Ah, so "local" moves relative to parent. I thought it moves relatively to its position. But anyway, SetRelative() solved issue for me - that also can be added to a sample collection :)

    Actually, not, because i can see a sprite at anytime, so its alpha is always 1. Tried a Rewind(), it didnt help.

    And an old good question: did you end up with solution for editing tween inside of sequence? For example, as i mentioned before, i have a tiles so they should jump all over the field, say, to the next empty cell. During the jump, they should go at least some scaling and moving, so i'd like to have a sequence. Jumps are launched quite often, so i'd like to cache a seq. The only problem is that the destination should change dynamically.
     
  47. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Can you send me a barebone example that reproduces the issue then? :) I tried to replicate it but everything works correctly here.

    About changing the values of a tween inside a Sequence, sorry but it's a no-go. There are so many things tied together in a Sequence that a ton of exceptions would result (like in case where an appended tween is actually based on the position of the previous one).

    P.S. I might be slow to answer until the weekend, because I'm packing and getting ready to fly to Serbia tomorrow morning (yey!).
     
  48. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    Okay, have a nice flight :)
     
  49. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Thanks! It will be a good day tomorrow :)
     
  50. Little-Big-Monkey

    Little-Big-Monkey

    Joined:
    Mar 4, 2014
    Posts:
    40
    Hello Izitmee !

    I'm still using HOTween, and I'm looking to migrate to DOTween. So I have some question :
    - Can we use DOTween in production, as it's still in alpha ?
    - Is there a migration tool ? As we have set lot of tween in script and in editor ..
    - Does DOTween have a component to setup tween in editor ? It's so usefull to easily and quickly set up a little tween (the most usefull is position, rotation and scale, ofc)

    Thanks !