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

    Paniku

    Joined:
    Apr 11, 2013
    Posts:
    24
    Hi, just curious why the Tweener isn't passed as a parameter in the TweenCallback delegate? Without it you'd have to do:

    Tweener tweener = null;
    tweener = DOTween.To(stuff).OnUpdate(() => Debug.Log(tweener.Elapsed));

    DOTween.To(stuff).OnUpdate(t => Debug.Log(t.Elapsed); is much nicer than the above.

    Would be nice if this could come in a future update, if possible.
     
  2. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Hello there

    Happy new year!

    Can I store a sequence without it animating? In other words I want my menu to animate only when a condition is met and was wondering how is a sequence stored for later use?

    These are the two values I want to animate:
    shapeHorizontalMenu is of type Horizontal Layout Group
    DOTween.To(x=>shapeHorizontalMenu.spacing=x,-28.2f,-132.5f,0.5f);
    shapeRectTransform.DOAnchorPos(newVector3(40f,0f),0.5f,false);

    Also how can I make sure the generic tween is smoothly reversed? Right now it kind of jumps abruptly when going from one value to another.

    Thanks
     
  3. SidarVasco

    SidarVasco

    Joined:
    Feb 9, 2015
    Posts:
    163
    @geganome

    Both DO animations return a Tween. You are also not specifying a sequence, ( at least not in code you are ) which is fine. But you can store the Tweens like so:

    Code (csharp):
    1.  
    2.  
    3. Tween to;
    4.   Tween aPos;
    5.  
    6. /// somewhere in your code
    7.  
    8. to = DOTween.To(x=>shapeHorizontalMenu.spacing=x,-28.2f,-132.5f,0.5f);
    9. aPos = shapeRectTransform.DOAnchorPos(newVector3(40f,0f),0.5f,false);
    10. to.Pause();
    11. aPos.Pause();
    12.  
    13. // Where you need them
    14.  
    15. to.Play();
    16. aPos.Play();
    17.  
    18. //Reverse
    19. to.Rewind();
    20. aPos.Rewind();
    21.  
    Wouldn't this make it less generic? The implication here is that the function should be
    Code (csharp):
    1. void TweenCallback (Tween t);
    This means that all your functions must have that parameter.
     
  4. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    @SidarVasco
    Thanks a lot for your help. I saved both my tweens and appended them one and insert the other at time 0f so they played at the same time in my sequence. Pretty cool to know you can store tweens in both generic and shortcut ways.

    Is there a way to add a delay like this?
    mySequence.PlayBackwards().SetDelay(1f);

    PlayForward() is fine but I need to add a delay to PlayBackwards()

    Thanks again
     
  5. abhijeet1001

    abhijeet1001

    Joined:
    Jan 6, 2015
    Posts:
    65
    Is there anyway to create dotween path waypoints during runtime ?
     
  6. XenoBits

    XenoBits

    Joined:
    Aug 28, 2014
    Posts:
    27
    Hello
    Sorry if it was already reported, I have big issues with DoShake methods on Windows universal builds.
    Most of the time the shake get stuck in the middle of the animation.
    I've encountered the issue with the 3 methods (position, scale, rotation) on DoTween v1.1.135 vanilla and compatibility build (and on the earlier version I was using so far)
    For now I'll use DoPunch instead which is working so far.
    I can provide more details if needed.

    Anyway thank you again for this wonderful tool
     
  7. deadlyboss

    deadlyboss

    Joined:
    Feb 8, 2015
    Posts:
    5
    Hello guys!

    I recently started using DoTween for animations in a game. The problem is, I can't figure out how to reset a sequence from the beginning after it has finished.

    Code (CSharp):
    1.     private Sequence _interdictionGlowSequence;
    2.     void ViewSetInterdiction() {
    3.         _interdictionSprite.gameObject.SetActive(_hasInterdiction);
    4.         _interdictionGlowSprite.gameObject.SetActive(_hasInterdiction);
    5.         if (_hasInterdiction) {
    6.             if (_interdictionGlowSequence == null) {
    7.                 _interdictionGlowSequence = DOTween.Sequence();
    8.  
    9.                 _interdictionGlowSequence.Append(_interdictionGlowSprite.DOFade(1.0f, 0.1f));
    10.                 _interdictionGlowSequence.AppendInterval(0.25f);
    11.                 _interdictionGlowSequence.Append(_interdictionGlowSprite.DOFade(0.0f, 1.9f));
    12.                 _interdictionGlowSequence.Play();
    13.             } else {
    14.                 _interdictionGlowSequence.Restart();
    15.             }
    16.         }
    17.     }
    Thanks in advance!
     
  8. Rustamovich

    Rustamovich

    Joined:
    Sep 5, 2014
    Posts:
    36
    Hi @Izitmee ! Thank you for your great plugin and support!

    Please, tell me from which point of time this yield construction waits not only completion of tween, but KILL too?
    yield return myTween.WaitForCompletion();

    The truth is that it works for me all this 5 months for only completed tweens, but some time ago it starts works for killed tweens too.

    Can I somehow rewind it?
     
  9. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Can I make a custom ease curve using DOTween?
     
  10. Sonoshee

    Sonoshee

    Joined:
    Jul 8, 2014
    Posts:
    77
    Manny Calavera and BTStone like this.
  11. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    I solved my custom ease curve by doing this:

    Code (CSharp):
    1. public AnimationCurve initialBounce;
    and then

    Code (CSharp):
    1. GetComponent<RectTransform>().DOScale(scale,1f).SetEase(initialBounce);
    Thanks
     
  12. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Aghrgh! Notifications didn't reach me once again and I was so busy with my current project that I didn't check the forums just to be on the safe side. Apologies! As a hint, if you don't see me answering within a couple days, come shouting at me on twitter (@demigiant), and I'll notice that :B

    @gegagome Glad you found the AnimationCurve ease option in the meantime. It can do pretty cool stuff :)

    @Sonoshee Woooh niiice! I never thought of using weird characters for the scramble effect like that, but it looks absolutely great! Thanks for sharing.

    @Rustamovich Ahoy! All yields now wait also for Kill other than for whatever yield you choose. Not doing that (in older versions) was actually a bug, because it caused the coroutine to wait forever in case you were waiting for an action and tween got killed in the meantime. I think I added the fix in DOTween v0.8.530, but I wouldn't recommend rewinding there, because tons of fixes and optimizations happened. You could instead check if a tween has been killed or not when moving beyond a Complete event.

    @deadlyboss Hi! A Sequence is automatically killed to free memory when complete, so you need to chain a SetAutoKill(false) to it if you want to reuse it. After that, Restart is the right choice.

    @XenoBits Agh, no, that is not a known feature. It seems very weird: I'll investigate.

    @abhijeet1001 Sure, you can use DOPath to create paths at runtime.

    @no1no Glad it's solved. Safe mode handles exceptions, but that means it kills tweens silently when something happens instead of throwing an error and blocking the whole game.

    @Paniku The previous version of DOTween (HOTween) passed Tweens in callbacks, but after much thought I decided to scrap that to keep things lighter, considering that usually the tween is not needed there.
     
  13. SidarVasco

    SidarVasco

    Joined:
    Feb 9, 2015
    Posts:
    163
    Awww all these answers but non directed at my problem T_T
     
  14. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @SidarVasco Aw sorry I missed that! I only saw you solving problems, not having them :p

    There was an old bug where tweens could start going faster and faster, which is now solved, but there is really no reason for a Sequence to go slower with each restart instead (and you code seems fine). The only thing that comes to my mind is that somehow you're changing Unity, DOTween, or the Sequences timeScale? Can you check that and let me know? And it it doesn't work, can you replicate it in a sample project somehow, and attach it here?
     
  15. SidarVasco

    SidarVasco

    Joined:
    Feb 9, 2015
    Posts:
    163
    Not touching any of that. It's practically a clean/new project.

    Ill see if I can make an example case for you. (not home right now )
     
  16. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Hi,

    I made several games on the Asset Store, and some use Dotween.

    I want to add an
    #if DOTWEEN
    ...
    #endif

    In my code to prevent some error.


    After the customer get the asset, and imported it in Unity (it's a complete project, so it erase all previous package when you import it), they have an error :

    "The type or namespace 'DG' could not be found ..."

    So far, everything is normal : They have to get Dotween.

    BUT my problem is here : when the user got it, they can't setup dotween because they have this error :

    "Type UnityEngine.SpriteRenderer" does not contain a member "DOColor"
    or
    "Type UnityEngine.SpriteRenderer" cannot be converted to UnityEngine.material

    I think preprocessor should be the solution. Any any idea how can I handle it for Dotween (who is the best tweener in the world for me;) ), or maybe you have another solution?

    Thanks a lot!

    Best regards,

    AB
     
  17. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @ababab5 Ahoy! :)

    Mhmm I could add a global Unity define when DOTween is setup, but I'm not sure it would be the best thing to do. Also, it feels very weird that your users can't setup DOTween because of errors: DOTween is an assembly, and as such the Setup panel should open anyway because it's independent from errors in the project. What happens instead? Is it not opening at all? Or something else?

    Other than that, the best solution I can think of is for you to include DOTween in your assets, which I suppose would make everything easier for everybody. I grant permission to do that (obviously not DOTween Pro), as long as you include the whole package along with the original readme file.

    Cheers :)
    Daniele
     
  18. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Hi,

    I just didn't know I can add dotween FREE in my project, great!

    Where can I find your email to send you the game in question to let you check the issue with the import.

    Cheers !

     
  19. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    DOTween FREE is completely redistributable, as long as it's redistributed "as is" without any changes :) And thanks a lot for asking and letting me know.

    Gonna write you a private message with my mail now ;)
     
    ababab5 likes this.
  20. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Last edited: Jan 19, 2016
    BTStone and ababab5 like this.
  21. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    It's totally normal to ask...

    cheers!
     
  22. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    I know, but it happens very rarely :p
     
  23. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Demigiant likes this.
  24. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Does DOTWEEN have something like this?

    Code (csharp):
    1.  
    2. DOTWEEN.Wait(0.5f).OnComplete(()-> CODE);
    3.  
    I frequently need something like this and does use fake tweens for this, which is ugly.
     
  25. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Demigiant likes this.
  26. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    :D Straight on!!!!
     
    BTStone likes this.
  27. no1no

    no1no

    Joined:
    Sep 15, 2015
    Posts:
    2
    Is there any way to re-init DOTween? The error might not be serious and I want to user to continue playing after they leaving the error scene. I tried to call init() again but it doesn't seem to work.
     
  28. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @no1no You can use DOTween.Clear to reinit DOTween, or DOTween.KillAll to kill all tweens (and thus get rid of eventual tweens with errors).
     
  29. Fuatnow

    Fuatnow

    Joined:
    Jan 21, 2016
    Posts:
    6
    Hi,lzitmee.I'm so glad to see you still active here.
    I have a problem using dotween,this is my code:
    void fun()
    {
    foreach (var gird in chainList)
    {
    [...]
    var seq = DOTween.Sequence ();
    var moveTo = gird.transform.DOMove (toPos, someTime);
    seq.AppendInterval (sometime).Append (moveTo).AppendCallback (() =>gird_moveEnd(gird));
    }
    }

    void gird_moveEnd(Gird gird)
    {
    [...]
    print(gird.Info);
    }

    when the callback executed , the param gird is not my sendered gird .
    I print the information of the param gird, all information is same.
    That is to see all gird in gird_moveEnd function is the same gird which was the last called.
    How can i sender the target to get it in callback function?
    Waiting for your urgent respond.
     
  30. Fuatnow

    Fuatnow

    Joined:
    Jan 21, 2016
    Posts:
    6
    i want destroy the target when the tween is end.
     
  31. Trinary

    Trinary

    Joined:
    Jul 26, 2013
    Posts:
    395
    The mono compiler that Unity uses has a bug when it comes to for or foreach loops. It doesn't properly box the context of the variables you are operating on in the loop. To get around this you can make a local copy of your gird variable before the lambda expression.

    So add a line inside the foreach somewhere: var girdCopy = gird;
    then pass girdCopy into gird_moveEnd rather than gird.
     
  32. Fuatnow

    Fuatnow

    Joined:
    Jan 21, 2016
    Posts:
    6
    Solved the problem, thanks a lot!
     
    Trinary likes this.
  33. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Trinary likes this.
  34. Fuatnow

    Fuatnow

    Joined:
    Jan 21, 2016
    Posts:
    6
    Sorry for disturbing you again.
    I encountering a new problem.
    I need make a gird move to other position (from one blank girdBox to another).
    I try this:
    Code (CSharp):
    1. float unitTime = 3.0f;
    2.         var move1 = g1.transform.DOMoveY (2.7f,  unitTime).SetEase(Ease.Linear);
    3.         var move2 = g1.transform.DOMoveY (1.9f,  unitTime).SetEase(Ease.Linear);
    4.         var move3 = g1.transform.DOMoveY (1.15f, unitTime).SetEase(Ease.Linear);
    5.         var move4 = g1.transform.DOMoveY (0.36f, unitTime).SetEase(Ease.Linear);
    6.         var move5 = g1.transform.DOMoveY (-0.4f, unitTime).SetEase(Ease.Linear);
    7.         var move6 = g1.transform.DOMoveY (-1.19f,unitTime).SetEase(Ease.Linear);
    8.         var move7 = g1.transform.DOMoveY (-1.95f,unitTime).SetEase(Ease.Linear);
    9.         var move8 = g1.transform.DOMoveY (-2.7f, unitTime).SetEase(Ease.Linear);
    10.         var move9 = g1.transform.DOMoveY (-3.45f,unitTime).SetEase(Ease.Linear);
    11.         var seq = DOTween.Sequence ();
    12.         seq.Append (move1).Append (move2).Append (move3).Append (move4).Append (move5).Append (move6).Append (move7).Append (move8).Append (move9);
    13.         var move10 = g2.transform.DOMoveY(-3.45f, 9*unitTime).SetEase(Ease.Linear);
    When game start , g1 and g2 init the same positionY, also they aim to same endPositionY.
    I found that they are not always have same positionY when moving, but at the end of time they have.

    Anther question , why DoMove's default ease type is not Ease.Linear?

    I'm a chinese ,my English is too bad , wish you can understand what i said.
     
  35. Fuatnow

    Fuatnow

    Joined:
    Jan 21, 2016
    Posts:
    6

    Ha, I see. the space distance is not equal!
     
  36. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hi @Fuatnow. Don't worry, I understand, and I'm Italian so my English is not that good either.

    Glad you solved the first issue. About the second, DOMove and every other tween use as default ease the one that you can set in DOTween's Utility Panel. By default it's set to OutQuad, because that's usually the most commonly used one, but you can change it.
     
  37. SirDorius9

    SirDorius9

    Joined:
    Feb 3, 2014
    Posts:
    10
  38. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hello @SirDorius9 I made a quick test, and I seem to get the desired effect with the following code:

    Code (CSharp):
    1.  
    2. public class DoTweenChase : MonoBehaviour
    3. {
    4.     public Transform _Target;
    5.     public float _Speed;
    6.  
    7.     void OnEnable()
    8.     {
    9.         Tweener Tween = transform.DOMove(GetTargetPosition(), _Speed).SetAutoKill(false).SetSpeedBased(true).SetUpdate(UpdateType.Late);
    10.  
    11.         this.AddLateUpdate((x) =>
    12.         {
    13.             Tween.ChangeStartValue(transform.position).ChangeEndValue(GetTargetPosition()).SetSpeedBased(true).Restart();
    14.         });
    15.  
    16.     }
    17.  
    18.     public Vector3 GetTargetPosition()
    19.     {
    20.         if(_Target)
    21.         {
    22.             return _Target.position;
    23.         }
    24.         return transform.position;
    25.     }
    26. }
    27.  
    Dont mind the "This.AddLateUpdate()" that is just something I use myself, instead, add that to your own LateUpdate. Hope it helps!
     
  39. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @SirDorius9 Wooops sorry for missing that, and thanks @JakeTBear for the solution :) It never occurred to me, but indeed a SetSpeedBased needs to be chained again in case of start/end value change to calculate it correctly.
     
  40. Dragonic89

    Dragonic89

    Joined:
    Jan 3, 2013
    Posts:
    48
    Hello @Izitmee

    I think I found a little bug for DOVirtual.DelayedCall on Android !

    I don't know why, but the delay parameter isn't working and it goes directly into the callback.
    (tested on my Zenfone 2 ZE551ML, Android 5.0, no problem in Editor)

    Code (CSharp):
    1.  debugText.text = "2";
    2. DOVirtual.DelayedCall(2.0f, () => {
    3.                 debugText.text = "3";//it appears immediately, not waiting 2 seconds
    4.             });
     
  41. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Dragonic89 Hello!

    Uhm, that is weird. DelayedCall just creates an empty Sequence in the background, and Sequences do work on Android without any problems. Are you sure that maybe you're not changing DOTween's timeScale on Android for some reason (DelayedCall is independent from Unity's timeScale, but not from DOTween's). Or maybe your'e calling that in the first frame of a new scene, and for some reason on Android that frame lasts for 2 seconds? Let me know.
     
  42. SenseEater

    SenseEater

    Joined:
    Nov 28, 2014
    Posts:
    84
    i imported latest version of DOTween Pro. i am getting error

    "Assets/Demigiant/DOTweenPro/DOTweenAnimation.cs(12,15): error CS0246: The type or namespace name `TMPro' could not be found. Are you missing a using directive or an assembly reference?"

    My Project is set to iOS. I tried removing DOTWEEN_TMP from script define symbols but that resulted in a whole bunch of errors thrown in telling that tk2d elements are missing DOFade , DOColor etc methods.

    I am using 2D Toolkit but i dont have TextMesh Pro in my project.

    Update : i tried to Comment out TMPro namespace in DOTweenAnimation.cs script which old error but now these show up :

     
    Last edited: Jan 24, 2016
  43. SenseEater

    SenseEater

    Joined:
    Nov 28, 2014
    Posts:
    84
    Update 2 : I have managed to get my project working by downloading DOTween straight from website but i still cant use the PRO version that i bought from store?
     
  44. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @KorakuBewan Hi! Uhm, that is very weird. Just to be on the safe side, I just tried creating an empty project with 2D Toolkit and importing DOTween Pro, and it setups correctly, without adding the DOTWEEN_TMP define, which is indeed related to TextMesh Pro. Are you sure you don't have a "TextMesh Pro" folder lying around in your project? That would trick DOTween into believing you have TextMesh Pro and setup accordingly. If so, can you delete it, completely delete Demigiant's folder (DOTween + DOTween Pro), then reimport DOTween Pro from the Asset Store and run the Setup from its Utility Panel?

    Let me know,
    Daniele
     
  45. HallbergIllustration

    HallbergIllustration

    Joined:
    Mar 15, 2015
    Posts:
    7
    Hi @Izitmee
    I have a question about a feature I'm about to make for a 2D game for iPad. Can I control the Tween Animation frame by frame, so when for example a player is physically rotating the iPad an output in form of an animation occurs, but when stopping the physical rotation the animation will also stop? I hope it makes sense. Thanks!

    //Kenneth
     
  46. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hi @KennethFaigh!

    If I understood correctly, you would simply like to pause/resume an animation whenever you want. If so, you can use DOPlay/DOPause (for DOTweenAnimations) or Play/Pause (for Tweens/Tweeners/Sequences).

    Cheers,
    Daniele
     
  47. HallbergIllustration

    HallbergIllustration

    Joined:
    Mar 15, 2015
    Posts:
    7
    Thanks for the great and fast answer @Izitmee
    My solution is going to be a bit different, but I actually have an example of the core feature. This is what I meant with my earlier message:


    //Kenneth
     
  48. kevincfy

    kevincfy

    Joined:
    Oct 12, 2012
    Posts:
    16
    Hi @Izitmee, is it possible to force DOTween to use frames instead of time? So force it to use a particular frame rate.

    The reason I ask is because we've built an app that uses DOTween for a lot of the animations and delayed calls to trigger events. But we're in the process of converting the app to 4k video by taking screengrabs every frame, but because writing the frames takes a lot of time the tweens are all out of sync.

    Realise this might be a fringe case!
     
  49. DanielVanches

    DanielVanches

    Joined:
    Apr 19, 2012
    Posts:
    38
    Hello!

    What would be the best/correct way to redistribute DoTween (the free version, of course) with a project?
    I'm curious since you need to run the setup process before use, and if I include the Demigiant folder prior to setup the user gets some errors (related to unavailable DoTween methods), but if I include it after setup the user gets a couple reflection errors that go away if you hit the Clear button.

    Thanks a lot.
     
  50. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @KennethFaigh Ah, I see now! And that example is very cool. Then, if you want to tell DOTween how much to advance frame by frame, you can:
    a) create the tween and set it in a paused state
    b) each frame, use myTween.Goto to tell DOTween how much to advance (for example, to advance by 0.2 seconds, you would do Goto(myTween.Elapsed() + 0.2f))

    @kevincfy I'm going to ponder about it, but I'm not really sure it's doable. Also, it would require you to change all your tweening code, since the duration instead of "seconds" would become "number of frames" and thus the values you have now wouldn't be correct anymore.
    Let me also see if I can find an alternate solution,. What you mean that all tweens are out of sync? All the tweens use a single update call, so they should always be in sync even with heavy stuttering. Do you mean they're not in sync with other non-tween animations that use a different time setting, or something like that? Also, one thing you could already try, is to check the "smooth delta time" option in DOTween's settings, which will make DOTween ignore frames that last beyond Unity's smoothDeltaTime max duration.
    Let me know!

    @DanielVanches Ahoy!
    The best approach would be to redistribute the after-setup version, ignoring those pesky Reflection errors. They're due to a bug in the latest Unity versions which I hope will be fixed soon, but since they're harmless and won't appear after that I'd assume users shouldn't be alarmed.