Search Unity

DOTween (HOTween v2), a Unity tween engine

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

  1. urbemAngeli

    urbemAngeli

    Joined:
    May 12, 2017
    Posts:
    61
    Hi! I am trying to rotate an object along the local Y axis through the DOLocalRotateQuaternion method. I want the object to rotate 360 degrees over and over. I tried to substitute different angles, but my object either twitches or does not rotate at all. If I use the DOLocalRotate method, a lock may occur and then the object will not rotate correctly. How to infinitely rotate an object along the local axis?
    Code (CSharp):
    1.         tween = target.DOLocalRotateQuaternion(Quaternion.Euler(0, 90, 0), 1 / speed)
    2.             .SetAutoKill(false)
    3.             .SetLoops(-1, LoopType.Incremental)
    4.             .SetEase(Ease.Linear)
    5.             .Pause();
     
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    From the docs:

    DORotateQuaternion:


    DOLocalRotate is more suitable, as it takes an extra parameter "RotateMode", which you can set to LocalAxisAdd or WorldAxisAdd for incremental rotations.

    http://dotween.demigiant.com/documentation.php#creatingTweener
     
  3. urbemAngeli

    urbemAngeli

    Joined:
    May 12, 2017
    Posts:
    61
    Thank you! It works.
     
    flashframe likes this.
  4. vladboroday

    vladboroday

    Joined:
    Jan 3, 2018
    Posts:
    5
    Hi. Got an issue. I'm spawning a prefab with visual dotween animations and trying to add them to the sequence like this.
    Code (CSharp):
    1.        
    2. private void Awake()
    3.         {
    4.             _sequence = DOTween.Sequence();
    5.             _sequence.SetAutoKill(isAutokill);
    6.         }
    7.  
    8.         private void Start()
    9.         {
    10.             foreach (DOTweenAnimation visualTween in visualTweens)
    11.             {
    12.                 if (visualTween.tween == null)
    13.                     visualTween.CreateTween();
    14.  
    15.                 if (!visualTween.tween.IsInitialized())
    16.                     visualTween.tween.ForceInit();
    17.                
    18.  
    19.                 _sequence.Join(visualTween.tween);
    20.             }
    21.         ...
    22.         }
    23.  
    Resulting sequnce has no tweeners added on Join method. Decompiling with rider show that a field sequence.active == false wich skips joining logic
     
  5. Lautaro-Arino

    Lautaro-Arino

    Joined:
    Sep 18, 2013
    Posts:
    93
    I am trying to use DoTween in a way that it may not be made for so ill ask about it here to see if its possible. Actually im pretty sure it is possible but i assumed that there where some functions to make it easier.

    So what i want is a visual effect like color or scale punch that loops. And i would want to be able to switch it on and of. That is, to make loop endlessy untill its switched of. When switched of it would tween back to its natural state, not jump back. An acceptable alternative would be if it played the current loop til l finish. When switched off it would be ready to go again.

    Any tips or tricks?
     
  6. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Color? Scale? Punch? Loops? Pause?
    Yes, everything you say you want to achieve is achievable with shortcut functions. Alas, there is no "Reify Imagination" button.

    Docs

    Try your hand at writing some code. I'll can help you with the bits you stumble with.
     
  7. Lautaro-Arino

    Lautaro-Arino

    Joined:
    Sep 18, 2013
    Posts:
    93
    I dont understand what reify imagination is? I do know about the Color, scale, punch and loop methods. What i mean is that i lack a native way of switching of and on tweens. So that they would loop forever when switched on and when switched of they would "cool down" and tween back to their original state. Im asking if there is a native smarter way of doing it, maybe some methods that are meant to help with this, or if i would just do it myself?
     
  8. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Okay I understand the question now. SmoothRewind() may be what you need.
    Code (CSharp):
    1. using DG.Tweening;
    2. using UnityEngine;
    3.  
    4. public class LooperDooper : MonoBehaviour
    5. {
    6.     private void Start()
    7.     {
    8.         var tween = transform.DOScale(new Vector3(2, 2, 2), 1).SetLoops(-1, LoopType.Yoyo);
    9.         tween.OnUpdate(() => RewindCheck(tween));
    10.     }
    11.  
    12.  
    13.     private void RewindCheck(Tween tween)
    14.     {
    15.         if (Input.GetKeyDown(KeyCode.Space))
    16.         {
    17.             tween.onUpdate = null; // we're done with this
    18.             tween.SmoothRewind();
    19.             tween.OnRewind(() => Debug.Log("This fires when you're back at the beginning"));
    20.         }
    21.     }
    22. }
     
    Lautaro-Arino likes this.
  9. Trickster511

    Trickster511

    Joined:
    Sep 2, 2014
    Posts:
    12
    Hi, I'm having a similar problem that gaterooze had, except it's also saying "'SpriteRenderer' does not contain a definition for 'DOColor' and the best extension method overload 'ShortcutExtensions.DOColor(Camera, Color, float)' requires a receiver of type 'Camera'" and a simple reinstall of DOTween doesn't work.

    Also setting the relativity to some of my tweens after appending them to a sequencer is not working, only when it's not in a sequencer, but one problem at a time.

    Edit: Disregard the 2nd problem, I fixed it, it was a typo on my part but I guess the code thought it was right so it never stopped me
     
    Last edited: May 31, 2021
  10. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    Have you checked that the Sprite module is installed in the DOTween Utility Panel?
     
  11. Trickster511

    Trickster511

    Joined:
    Sep 2, 2014
    Posts:
    12
    I have and it is
     
  12. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    Can we see some code?
     
  13. Trickster511

    Trickster511

    Joined:
    Sep 2, 2014
    Posts:
    12
    Here's an example of one line of code that's being affected:
    https://pasteboard.co/K4vlFAy.png
    And here is the error it's outputing:
    https://pasteboard.co/K4vmmoe.png

    Edit: So I don't know what I did different, but the problem seemed to have solved itself. The errors are gone and I don't know why they appeared in the first place or why they disappeared now. I'll chalk it up to Unity and/or Visual Studio Code being weird lol
     
    Last edited: Jun 1, 2021
  14. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I am using DoPath as SideScroller2D with SetLookAt, but when I apply it in the game the rotation of the gameobject happens in both Y and Z axis.

    transform.DOPath(path, speed, PathType.CatmullRom, PathMode.Sidescroller2D, 2).SetSpeedBased(true).SetEase(Ease.Linear)
    .SetLookAt(0.1f)

    this is causing problem with the current Unity 2DRenderer as the lighting gets messed up if Y rotation becomes -180.

    Is there way to lock X and Y rotation and only use Z rotation to do SetLookAt? I tried to use SetOption, but when I lock it using it, the sprite does not rotate at all.
     
  15. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    Have you tried the AxisConstrain parameter of DOPath?

    Code (CSharp):
    1. transform.DOPath(path, 4f).SetOptions(false, AxisConstraint.None, AxisConstraint.Y);
     
  16. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Like I said in my post. I did try it. When you use it, lookat totally breaks down.
     
  17. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Lookat should not use y rotation of -180 to flip the sprite...
     
  18. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    FuguFirecracker likes this.
  19. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Hey! An animated gif would go a long way towards me understanding what you're talking about. I'll also accept a series of still frames or an interpretative dance.
     
    HarryChew likes this.
  20. Lautaro-Arino

    Lautaro-Arino

    Joined:
    Sep 18, 2013
    Posts:
    93
    Is it possible to change the parameters of a tween while it's playing? For example if it's looping. Or maybe make it seem like it's been changed?
     
  21. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Code (CSharp):
    1.  
    2. tween.ChangeEndValue(newValue, true);
    3. tween.ChangeValues(newValue, true);
    4. tween.ChangeStartValue(newValue, true);
    EDIT:
    For all the "Can you do this?" posts:

    i) make a tween variable. eg: var tween = ...
    ii) write the name of your variable followed by a dot . eg: tween.
    iii) wait for your ide to populate a list of all the methods and properties you have at your disposal.
    iv) use the down-arrow key to scroll through said properties and methods and read the popup docs.
    v) ???
    vi) profit

    whatcandotweendo.png
     
    Last edited: Jun 5, 2021
  22. JuniorLongfellow

    JuniorLongfellow

    Joined:
    Feb 27, 2013
    Posts:
    19
    Is there a more "friendly" version of the documentation that isn't the homepage? Can't read it without spamming a million expand buttons..jeeze, they're not spoilers.

    Edit:
    Tweaked the CSS a bit, you can apply it via a browser extension

    Code (CSS):
    1.  
    2.  
    3. nav, #sidebar, .back-to-top {display: none; }
    4. #pageWrap { width: 100% }
    5. #main { width: auto; margin: 20px; }
    6. dl.api dd{ display: block; }
    7. .expand-bt { display: none; }
    8. .csharp.hljs { filter: invert(1); }
    9. dl.api dt a{ background: antiquewhite; padding: 10px; font-weight: bold; }
    10. #main .splash { text-shadow: none; background: #333; }
    11. dd { position: relative; }
    12.  
    13.  
     
    Last edited: Jun 6, 2021
  23. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    I am making a retro style game with a virtual resolution of 480x270. To make all my movements pixel perfect and without stuttering I am rounding all my movement to whole pixels of my virtual resolution. Now I also want to do this for DOTween, is there a way to do this?
     
  24. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    I am unaware of any builtin methods to jump to uniformly defined grid positions [ whatever unit you define as your "pixel" ] Tween engine; As in : Movement between points in space.

    You could write a Sequence moving your object one "pixel" increment per tween with a miniscule delay and even more miniscule duration ... That would appear as if your objects were "snapping to pixels" if done with a careful eye.

    But if you're gonna do that, you just might as well set the transforms directly in a couroutine that yields only slightly to get the effect you want.


    If I HAD to use DOTween to do this -and I'm not saying I that I necessarily would - I would write an custom Method that divided the tween distance parameter by your "pixel" size -rounding off to whole pixel- and plotted a series of points along the way to get to that end destination. Possibly with a custom Ease.
     
  25. farazk86

    farazk86

    Joined:
    May 31, 2017
    Posts:
    195
    Thank you, this is greatly helpful :)
     
    AlejMC likes this.
  26. Todiloo

    Todiloo

    Joined:
    Jan 22, 2016
    Posts:
    53
    Pretty new to dotween. Any tips on getting a position on a path based on a percentage?
    So basically I have a path I want to use for spawning enemies. And to get them evenly spaced out on a path I want to do.

    path.getpositionfrompercentage(enemyindex/totalnumberofenemies).position
    Can DOTween be used for that?
     
  27. simpleyuji

    simpleyuji

    Joined:
    Jun 11, 2017
    Posts:
    2
    Im doing a custom property tween that looks something like. However i want to be able to stop this tween as well. The function returns a TweenerCore instead of an int that i can use for DOTween.Kill(id) so not sure how to best stop this tween.

    Code (CSharp):
    1. DOTween.To(() => rt.offsetMax, x => rt.offsetMax = x, new Vector2(-parentRectTransform.sizeDelta.x, rt.offsetMax.y), 5.0f)
     
  28. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    Use SetId()

    http://dotween.demigiant.com/documentation.php#options
     
  29. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
  30. wechat_os_Qy0_83bdG0M5y9Psxq8uvKE0s

    wechat_os_Qy0_83bdG0M5y9Psxq8uvKE0s

    Joined:
    Jun 22, 2021
    Posts:
    1
    can be used in Unreal Engine?
     
  31. _Exerion

    _Exerion

    Joined:
    Dec 3, 2014
    Posts:
    12
    Btw, what is a "Flash" easing type? What's the difference with Linear?
     
  32. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
  33. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
  34. _Exerion

    _Exerion

    Joined:
    Dec 3, 2014
    Posts:
    12
  35. _Exerion

    _Exerion

    Joined:
    Dec 3, 2014
    Posts:
    12
    Turns out "Flash" is "Flicker"
     
  36. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    What is the logic of using tweens so a pool of 200/20 is enough?

    For example for a menu scale up and down tween. I would create the tween, play it, then kill it manually? Or should it get killed automatically even if the canvas component gets disabled?

    What if that same tween gets used every time that menu appears? Should I recycle it and if yes how? Does it need an ID? Or if not killed is it recycled automatically?

    Seems no matter what I do I get the warning that dotween has to create more and more tweens seemingly having more and more in memory even though no new or more tweens are needed.
     
  37. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Pool increase warnings are indicative of tweens being created ad nauseum in an update loop.
    Stop creating tweens in an update loop && || stop using coroutines to control your tweens.

    "But I'm not doing that!" you say ..
    Yes you are. If you don't know where all these tweens are coming from, you most certainly are. You just don't know it.

    *Edit
    Calrification: I said IF you don't know... If you do know , then it's something else ;)
     
    el_Guero likes this.
  38. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    I’m actually using Playmaker to code and since it’s based on state machines we almost don’t use update loops respectively we have code only running while a particular state is active.

    So no. It’s not an update loop in this case which is why I’m asking what the logic is of using tweens. Because somehow they get added more and more and add up.
     
  39. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    I'm going to be blunt here; don't take it personally.
    You don't fully understand what you're doing.
    You have ceded control of your code execution to a series of "black-boxes" [ pool manager and playmaker if I recall ].

    No. No they don't... This happens to you for reasons outlined above.
    This doesn't happen in a properly designed codebase. To be clear, the improper codebase is of your manufacture.

    Actually, I can't say that it's your fault with unrelenting certainty... Who knows what kind of lousy Playmaker / PoolManager functions run under the hood.

    Long story short [ for the 3rd time ] : It's not what DoTween is doing ... It's what you're doing.

    I hope we can still be friends ;)
     
    BTStone likes this.
  40. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    Lol take it easy. I know that it's my own code and setup I never said that the problem lies with dotween. Nonetheless, I'm trying to find a solution to the problem which is why I wrote before and now I came here to ask for help.

    And I would like to fully understand the base logic of how a tween flow is setup. I don't find anything about it in the documentation that helped me to get on the right track. I'm confused between auto kill, manual kill and recycle, that's all I think and I would appreciate if you could outline it too me (with apple and pears).

    No need to start dissing me or other devs (playmaker, poolboss etc) out there. I'm in love with Dotween as everyone else I just need to find a solution to this problem :)
     
  41. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Truly, t'was not my intent. Just some tough-love ;)

    It is not possible for me to tell you how to use DoTween harmoniously with two other plugins of with I have zero experience.

    Hit 'Expand All' to check out the CONTROL METHODS documentation.

    I recommend changing your DOTween settings to autokill ... This will kill the tween upon completion.
    I use this because -generally- I want my tween to do what I told it to do and then go away ... IF I need to interrupt said tween [ to assign new arguments or whatnot ] I'll kill it manually and assign a new tween to the tween variable.
    Use manualKill if you want to keep the tween in memory to rewind and play again and the like.
    Use recycle if you are sending the same values to the same objects repeatedly and you want to save memory.

    Hope this helps somewhat, but your control over your tweens may be limited to what your plugins are deciding to do with them.
     
    el_Guero likes this.
  42. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    Awesome, that makes more sense to me.

    And just ignore that I'm using Playmaker and other plugins which I think you have some prejudices for them. Playmaker is simple c# so whatever you do in a normal monobehaviour c# script I can do in Playmaker as well. Meaning the logic stays the same (the code too).

    So in the case I outlined above, when popping up a UI button with a tween scale, if I understand you correctly, you would just scale it up and not do anything afterwards (since it's autokilling it anyways if I enable this on initialization).

    Nonetheless, as said before, I use this scale tween on every game round, so according to your explanation, it would make sense to recycle it because when I show that UI again, I re-scale the button to zero beforehand and then apply the same tween again.

    In both cases, does it makes sense to give it an ID? or better question maybe is: is it good practice to give all tweens an ID?

    And (I promise) last question: if I have for example a rotation tween applied to my coins, if I give it an ID, can all my hundreds or thousand of coins use that same tween or will it automatically create the same amount of tweens for the objects I have so each one can rotate infinitely?
     
  43. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Do these plugins require || generate gameObjects in the hierarchy? If so ... they are getting updated in the update loop. What else are they updating in the update loop? I don't know. I's an unknown variable. I sincerely doubt, however, that the answer is "nothing". So it's not prejudice against any plugin, it's the fact that I can't rule out their interference.

    Seems like a likely course of action. You may want to reset the gameObject to default values in the OnComplete() callback method, so it's good to go when you need it again.

    No .. Let it go. Unless you're continuously having that UI come on / come off the screen. If you don't see that thing again for at least another second ... kill that tween.

    Oooo... This is a coding convention question. Let the fights begin !!! lol
    I rarely use IDs ... I tend to use functional methods that return the tween, so I always [ not always ] have a reference to it. So , IDs are kinda extraneous to my style. Having said that, if you need `em, use `em. Be careful about different game objects or instances of gameobjects using the same ID, unless your goal is to have them all do the same thing when you issue your orders.

    Hundred of thousands, you say ? I think we found out why you keep exceeding your tween pool. ;)
    Each object will require it's own tween. The ID is a convenience to effect all ID members when you call the static function on that ID.
     
    el_Guero likes this.
  44. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
    Hi all!

    I cannot seem to get ahold of the creator of Dotween. Is he still around? I have a reproducible bug that needs fixing and I don't know what to do since I cannot get ahold of him.
     
  45. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Yes. All the information you need to get in contact is here : Direct Support [ Scroll to the bottom of the page ]
     
  46. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
    Thanks for the quick reply! I have emailed him multiple times over the past few months but I haven't received a response yet. (I use to receive responses within a week). I will try again, thanks!
     
  47. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    He's still about. I was in contact with Daniele as recently as a couple of weeks ago.
    Try twitter or the contact form.
     
  48. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
    Will do, thanks!
     
  49. nareshbishtasus

    nareshbishtasus

    Joined:
    Jun 11, 2018
    Posts:
    36
    Hi, How can I add a delay after the tween has completed and before the OnComplete callback has called without using sequence or coroutine?

    Is there anything like SetDelayAfterCompleted() which I can add to this code to get the result?

    Img.DOFillAmount(SetPoint, TweenTime).SetEase(EaseType).OnComplete(() => IsQuestComplete(QuestRH, QuestInfo));
     
    Last edited: Jun 30, 2021
  50. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Not built in, but you can leverage DOTween's internal sequence coroutines to hack it ...

    From the docs: "TIP: You can create Sequences made only of callbacks and use them as timers or stuff like that."
    Code (CSharp):
    1.        transform.DOMoveX(12, 3)
    2.             .OnComplete(() => DOTween.Sequence().Play().SetDelay(2).OnComplete(() => Debug.Log("Pudding")));
    3.  
    4.         // OR!!!
    5.  
    6.         transform.DOMoveX(12, 3).OnComplete(() => DoDelay(2, () => Debug.Log("Pudding")));
    7.     }
    8.  
    9.     private  void DoDelay(float delay, Action action)
    10.     {
    11.         DOTween.Sequence().Play().SetDelay(delay).OnComplete(() => action());
    12.     }
    OR !!

    I would write an extension method with fluent interface to add this functionality ... If you don't know what that is, go with one of the two snippets above. Or something entirely different! Lots of ways to do stuff ;)
     
    andreiagmu likes this.