Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

DOTween (HOTween v2), a Unity tween engine

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

  1. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    It's been said that "unnecessary performance optimization is the root of all evil" !
    Who said that? Mighta been me ..

    Kidding aside, the general rule of thumb is that you should only concern yourself with such things if you really need it.
    If you're 2 frames shy of 60 at runtime, you might want to look at squeezing every little optimization you can, but other that that, let it be.

    And I know ... I hate it too when 'experts' chime in with answers that don't actually answer the question ...
    I'm usually thinkin' "I asked for an answer not a damned opinion !" ;)

    My actual answer is : I don't know. I've never ever found it necessary to benchmark this.
     
  2. watchagames

    watchagames

    Joined:
    Oct 1, 2017
    Posts:
    7
    Actually Im doing massive battles with a lot of projectiles..;-)
    Anyways my pb is that the SetCapacity does not look like to change the pre-allocated capacities ;-)
     
  3. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    Please post the complete method you are using to generate the tweens for your projectiles.

    Use the code tags - Available in the text editing toolbar
    Do not post an image of your code.
     
  4. watchagames

    watchagames

    Joined:
    Oct 1, 2017
    Posts:
    7
    Here but that's not my pb:

    Code (CSharp):
    1.             Sequence mySeq = DOTween.Sequence();
    2.             mySeq.Append(gameObject.transform.DOMove(destPos, durationInSeconds, false));
    3.             mySeq.PrependInterval(startDelayInSeconds);
    4.             mySeq.OnComplete(cbHurlDone);
    5.             mySeq.SetAutoKill(true);
    6.             mySeq.Play();
    7.  
    I know I'm spawing a lot of projectiles, my pb is to prepare the best DoTween for those situations ;-)
     
  5. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    Okay missing the access modifier, the return type, the method name, and the parameters ... but is a good start ...

    Where are you calling this method? And it DOES matter and it IS your problem if you are calling all these Sequences in Update or Update is calling the method that creates all these Sequences.

    DoTween will NEVER make enough tweens to keep up with the update loop.

    So .. How are you creating these Sequences ?
    How do you make 60,000 tweens ?
     
  6. watchagames

    watchagames

    Joined:
    Oct 1, 2017
    Posts:
    7
    I have battles with 500 + entities who can throw each big powers made of 100 projectiles ;-)
    For sure I will optimize those visuals in the future but for now I'm trying to solidify my runtime to handle extreme situations./
     
  7. LuckyDavid

    LuckyDavid

    Joined:
    Jun 25, 2019
    Posts:
    3
    Usually when using DoTween checking if my eularAngle is exactly at something after rotation works out fine and comes out true. The issue is when I use DoTween to rotate to something such as to 45 degrees it doesn't seem to actually be at that exact number. I even tried printing what my angle was and it said 45 so I tried an if that was always running and it would print something if my angle equaled 45 but it never became true. I think that my angle might be somewhere ever so slightly higher or lower than 45 but I'm not sure why it would do that. Do I just need to deal with the fact that sometimes the angle wont be perfectly exact and adjust my code to that?
     
  8. namcap

    namcap

    Joined:
    Jan 8, 2016
    Posts:
    20
    I'm seeing an error in Visual Studio after upgrading to Unity 2020.2. This isn't a compiler error and everything still works as expected, but Visual Studio cannot find the method:

    'CanvasGroup' does not contain a definition for 'DOFade' and the best extension method overload 'ShortcutExtensions.DOFade(Material, float, float)' requires a receiver of type 'Material'

    This is the same error that is seen in this GitHub issue.

    Is this 2020.2 specific, or is there a known fix for this? No changes have been made to the DOTween package -- the only change I made was upgrading my version of Unity.
     
  9. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    496
    This is likely floating point imprecision and not exclusive to DOTween. Unity will usually warn you not to compare floats for equality. You can use Mathf.Approximately(float a, float b) to compare floats. The == operator for Vector3 / Vector2 has this built in.

    https://docs.unity3d.com/ScriptReference/Mathf.Approximately.html
    https://docs.unity3d.com/ScriptReference/Vector3-operator_eq.html
     
  10. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    272
    Hello,

    On DoTween (free) I notice that tweens continue playing despite the Pause when the Editor's Pause is triggered by Playmaker (on purpose with Breakpoints or because of an error). Is there a way to have tweens paused by Playmaker too, an option I might have missed in the settings?
     
  11. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Is it possible to offset the starting part of a tween sequence? For instance, if I have many powerups that bob up and down, I might want to have them offset from each other slightly for a nicer visual effect, is there a way of setting how far along in the tween it begins?
     
  12. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    Check out the docs on Sequences
    Try your hand at writing some code; Comeback and post your code if you need pointers.
     
  13. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    You have not missed any hidden 'Playmaker' settings.
    Perhaps the Playmaker people may be of assistance.
    I think more Playmaker people are DoTween people than DoTween people are Playmaker people*

    All poodles are dogs, but not all dogs are poodles.

    *I have no statistical information to back up this dubious claim that I apparently made up right on the spot.
     
  14. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I am writing code right now, I just couldn't find any setting that might allow for this.
     
  15. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    Code (CSharp):
    1. mySequence.Append(transform.DOMoveX(45, 1));
    2. mySequence.AppendCallback(MyCallback);
    3. mySequence.AppendInterval(interval);
    4. mySequence.Insert(1, transform.DOMoveX(45, 1));
    5. mySequence.InsertCallback(1, MyCallback);
    6. // The rotation tween will be played together with the movement tween
    7. mySequence.Append(transform.DOMoveX(45, 1));
    8. mySequence.Join(transform.DORotate(new Vector3(0,180,0), 1));
    9. mySequence.Prepend(transform.DOMoveX(45, 1));
    10. mySequence.PrependCallback(MyCallback);
    11. mySequence.PrependInterval(interval);
    12.  
    All good stuff
     
  16. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I'm not entirely sure what's happening here? I'm doing, like:
    Code (CSharp):
    1. void Start()
    2.     {
    3.         transform.DOMove(new Vector3(0, 0.5f, 0), 1).SetEase(Ease.InOutSine).SetLoops(-1, LoopType.Yoyo).SetRelative();
    4.     }
    It just endlessly bobs the item up and down, but everything obviously bobs up and down at the same time, whereas I'd like to add a value manually to each object that would allow for the tween to start at a particular point in the sequence... this is not to be confused with the starting position, I obviously want the origin of the tween to be the same, but the percentage of completion be set at the very beginning.

    EDIT: .Goto(float, bool) does exactly what I need.
     
    Last edited: Jan 13, 2021
  17. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    I'm guessing that this is the monobehaviour you have on every one of your gameObjects ...
    Of course they are all gonna do the same thing. You need a mechanism by which you pass unique values to your objects.

    This could be as simple as setting a public "Delay" float in the inspector and assigning each delay individually.
    Code (CSharp):
    1.  public float Delay;
    2.      
    3.         void Start()
    4.             {
    5.                 transform.DOMove(new Vector3(0, 0.5f, 0), 1)
    6.                     .SetEase(Ease.InOutSine).SetLoops(-1, LoopType.Yoyo)
    7.                     .SetRelative()
    8.                     .SetDelay(Delay);
    9.             }
    This would be the naïve way of doing such things, but if you're just starting out programming, this might be the way that makes sense to you.

    A more sophisticated mechanism would be to create a system [ not a monobehavior] that receives a collection of transforms and either applies a separate timed tween to each transform; Or alternatively manages a single sequence to achieve the animated effect you're looking for
     
  18. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I already said that
    Goto(float, bool) 
    does exactly what I need. This has nothing to do with being naive or a beginner programmer, this is just an extremely simple visual effect for a power-up that requires a simple solution.

    I suppose if I wanted to space the positions out automatically I might add themselves to a big array at the start of the scene and apply a modulo-based increment to each powerup, but even that might not be sophisticated enough?

    But ultimately .Goto was what I was looking for, and I didn't find it buried in the documentation at all, it was a forum post Google found from four and a half years ago: https://forum.unity.com/threads/dotween-hotween-v2-a-unity-tween-engine.260692/page-48#post-2749883
     
  19. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    You're welcome
     
    Zebbi likes this.
  20. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Thanks for the suggestions, using a system to offset the tween position would be a great idea, although the YoYo loop I’m using still might make it tricky to determine the starting position for the return tween. Appreciate the help!
     
    FuguFirecracker likes this.
  21. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    Please know that I was not calling you "naïve". I have no idea of anyone's level nor abilities. Shoulda went with "the-simple-but-not-really-that-great-way-to-accomplish-this". I did give you two choices, the "easy way" and the "right way" ;)

    Really do take a look at Sequences ... Insert() and Append() are predictable means to get things to do what you want when you want them to do it.
     
    Zebbi likes this.
  22. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    This might do exactly what you want to do :

    Code (CSharp):
    1. public class SortaSineAnim : MonoBehaviour
    2. {
    3.     public Transform[] Transforms;
    4.  
    5.     public float Rise = 3;
    6.     public float Speed = 2;
    7.     public float Tweak = 0.486f;
    8.  
    9.     private void Start()
    10.     {
    11.         DoTheWave();
    12.     }
    13.  
    14.     private void DoTheWave()
    15.     {
    16.         for (var i = 0; i < Transforms.Length; i++)
    17.         {
    18.             Transforms[i].DOMoveY(Rise, Speed)
    19.                 .SetDelay(i * Transforms.Length *.01f + Tweak) // We wanna divide by the number of transforms
    20.                 .SetLoops(-1, LoopType.Yoyo)                   // But we wanna avoid divide by zero...
    21.                 .SetEase(Ease.OutSine)                         //  so *times and shift the decimal.
    22.                 .SetSpeedBased();
    23.         }
    24.     }
    25. }
    dothewave.gif
     
    Last edited: Jan 14, 2021
    Zebbi likes this.
  23. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Thanks for clarifying! Also, I didn’t mean to come as so rude, so sorry for sounding like an ass

    Wow that looks perfect, thank you! You’re right, delay would be much better for this since Goto can only work for the first half of the tween and has to be manually set. Out of interest, this appears to be a monobehaviour? Or is this more like the second example you mentioned?

    Thanks again!
     
    FuguFirecracker likes this.
  24. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    For simplicity it's a monobehaviour that you can attach to a control object in your scene. Lots of times I'll just stick a script on the main camera and check out the predicted behaviours when quickly prototyping and tweaking the variables.

    This can easily be a simple Object in your project and doesn't have to live in your scene.
    you can hard code constants or pass the animation parameters in the constructor.


    Code (CSharp):
    1. public class SortaSineAnim
    2.     {
    3.         public float Rise { get; set; }
    4.         public float Speed { get; set; }
    5.  
    6.         private const float TWEAK = 0.486f;
    7.  
    8.         public SortaSineAnim(params Transform[] transforms)
    9.         {
    10.  
    11.             for (var i = 0; i < transforms.Length; i++)
    12.             {
    13.                 transforms[i].DOMoveY(Rise, Speed)
    14.                     .SetDelay(i * transforms.Length * .01f + TWEAK)
    15.                     .SetLoops(-1, LoopType.Yoyo)
    16.                     .SetEase(Ease.OutSine)
    17.                     .SetSpeedBased();
    18.             }
    19.         }
    20.  
    21.      
    22.     }
    You can reuse this for everything you wanna undulate in sync .

    Call As such with Initializers :

    Code (CSharp):
    1.  
    2.         var ssa =   new SortaSineAnim(Transform1, Transform2, Transform3, etc) {  Rise = 3, Speed = 2.25f  };
    3.        
    Or go ahead and make it a static class. Add some more methods to pause || rewind || blow S*** up ... whatever suits your purpose.
     
  25. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    272
    Oh it's not much of a big problem either, I certainly acknowledged this and arranged my workflow around this. Is that because we're dealing with separate DLLs that don't know each other exist?
    I haven't been able to test DoTween outside of Playmaker so I don't know how it behaves in pure Unity's version of c# code.
     
  26. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    496
    It would be great if there were better search tools for the forums, because I answered this question about a month ago

    #3420
     
    sarynth, FuguFirecracker and Zebbi like this.
  27. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Haha, thanks, I think it's a little hard to figure out how to describe it exactly, starting phase is actually really good!
     
    flashframe likes this.
  28. CaptainChristian

    CaptainChristian

    Joined:
    Apr 3, 2013
    Posts:
    99
    Hi, what could be the reason why a fade animation on a tesmeshpro-ui element correctly sets the alpha, while on another component it keeps alpha at 0? I just copied the component without changing anything else.
     
  29. sarynth

    sarynth

    Joined:
    May 16, 2017
    Posts:
    98
    I have a canvasGroup. I set... canvasGroup.DOFade.

    I added this to a sequence. DOTween.Sequence().Append(...).AppendInterval(2f).Append(...)

    I'm now trying to cancel this if the player changes scenes.

    I've tried...
    DOTween.Kill(canvasGroup);
    DOTween.Kill(theTweenerCore);
    DOTween.Kill(theSequence);

    None of these seem to work.

    DOTween.KillAll() works. But, I don't want to kill all. Just the right things.
    DOTween.PlayingTweens() returns an array that includes the one I want to kill.

    How am I supposed to use the DOTween.Kill?

    Edit: If you would like me to paste more code, just let me know.
    Edit2: RESOLVED! This is Beautiful. Just found SetLink(...)

    Code (CSharp):
    1.     public TweenerCore<float, float, FloatOptions> FadeIn(CanvasGroup canvasGroup)
    2.     {
    3.         return canvasGroup.DOFade(1, 0.5f).SetEase(Ease.OutQuint);
    4.     }
    5.  
    6.     public TweenerCore<float, float, FloatOptions> FadeOut(CanvasGroup canvasGroup)
    7.     {
    8.         return canvasGroup.DOFade(0, 0.75f).SetEase(Ease.InOutQuad);
    9.     }
    10.  
    11.     public void FadeInOut(CanvasGroup canvasGroup, float showDuration = 2f)
    12.     {
    13.         DOTween.Sequence()
    14.             .Append(FadeIn(canvasGroup))
    15.             .AppendInterval(showDuration)
    16.             .Append(FadeOut(canvasGroup))
    17.             .SetLink(gameObject, LinkBehaviour.KillOnDestroy);
    18.     }
    (I have the FadeIn/FadeOut separation since I have some cases where I use it directly and wait for user input. Really nice and easy to separate, while still reusing. Thank you DOTween!)
     
    Last edited: Jan 14, 2021
    flashframe likes this.
  30. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    I am forever linking to my "Rotate Around" post.
     
    flashframe likes this.
  31. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Shame there isn't a pinned posts per thread, kinda like how discord has pinned messages.
     
    flashframe likes this.
  32. watchagames

    watchagames

    Joined:
    Oct 1, 2017
    Posts:
    7
    Hi,

    You can also kill a tween from its gameobject transform:

    gobj.transform.DoKill()
    this will automagically kill the right tween
     
  33. RebelBinary

    RebelBinary

    Joined:
    Aug 12, 2015
    Posts:
    8
    Having an issue with Dotween speeding up every time Unity live recompiles

    Save any script in play mode unity pauses and recompiles and when it resumes all my tweens double in speed. Is there a way to fix this ?
     
  34. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    I don't know why you're editing and saving scripts in playmode; I'm sure you have your reasons.

    While it is certainly possible to build code into your scripts that safeguards against the behaviour you describe, the recommended course of action is: Don't do that.

    If you insist on doing as such, you should look towards resetting the tween ( or values thereof) in OnEnable.
     
  35. RebelBinary

    RebelBinary

    Joined:
    Aug 12, 2015
    Posts:
    8
    You kidding? The time saved by not having to reload your game when you write code through live recompile is immense and it's party of Unity, it's just most people don't use it properly or at all since it nullifies globals and certain non serializable data structures which have to be reset on OnEnable. My projects fully supports it and it work seamlessly without problem, I recommend anyone give it a try on a new or simple project.

    Anyways, this does not affect just existing tweens, but new ones created after the live recompile. The timescale in Dotween is set to 1 but it behaves as if it's at a lower timescale.

    Put this code in and edit the script in play mode and you will notice the timescale for Dotween changes

    Code (CSharp):
    1.     void OnEnable()
    2.     {
    3.         float someValue = 0f;
    4.         float startTime = Time.time;
    5.         DOTween.To(() => someValue, x => someValue = x, 1f, 1f)
    6.                          .OnComplete(() => { Debug.Log($"Dotween TimeScale: {Time.time - startTime}"); });
    7.     }
    On start I get
    Dotween TimeScale: 0.9923458

    Subsequent live recompiles get
    Dotween TimeScale: 0.5791121
    Dotween TimeScale: 0.3533325
    Dotween TimeScale: 0.3533344

    This is a bug in Dotween and it should be fixed
     
    Last edited: Jan 20, 2021
  36. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    Oh! My mistake. I thought your question was "Why doesn't my code behave the way it is supposed to be behave while I'm actively editing my code"

    Apparently, it doesn't.
     
  37. RebelBinary

    RebelBinary

    Joined:
    Aug 12, 2015
    Posts:
    8
    You're being condescending for something reasonable I'm looking to support. Live recompile despite it's flaws is perfectly fine and my project fully works while doing it. I use a lot of plugins and assets and I haven't had any major issues apart from Dotween's timescale issue and a mobile services asset that simply needed to reinstate it's global variables OnEnable. Recompiling scripts in play mode is an amazing and liberating development experience akin to edit and continue in Visual Studio C# and C++ which I've grown accustom to in prior projects. There's no reason such a valuable and widely used asset such as Dotween can't support it fully either.

    In the meantime the work around is to simply set Dotweens timescale to the tested value

    In the future please refrain from posting if you can't offer constructive feedback.
     
  38. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    If you say it's "the bees' knees", I'll take your word for it.
    I did say in my initial post that you must have a reason for do so ...

    I have not attempted to live code any of my projects, so perhaps I am overly ignorant in this regard.
    Can you point me toward any pertinent articles || postings on the topic ?
     
  39. RebelBinary

    RebelBinary

    Joined:
    Aug 12, 2015
    Posts:
    8
    I don't blame you, most of the articles on the subject are on how to disable live rebuilds in play mode and the majority of people don't use it. I forgot where I found the article that allowed me to figure it out but will post it if I find it.

    A project has to be carefully maintained to remain functional with live recompile.

    The basics are this:
    1) Live recompile sets all global variables to null but retains all objects states and serializable data structures (Arrays,Lists). Dictionaries for example are nulled. Structs not set to [Serializable] will be reset to default values.
    2) OnDisable and OnEnable events are called before and after live recompile this is where you can reset your globals or copy non serialized data structures into serialized ones in OnDisable and reset them in OnEnable
     
    FuguFirecracker likes this.
  40. MiguelBest

    MiguelBest

    Joined:
    Oct 22, 2018
    Posts:
    11
    Hi, I'm trying to scramble an empty string to a new string ("Banana") and I would like for it to gradually increase the character length as each character is scrambled and revealed. I've tried the following:

    Code (CSharp):
    1. title.DOText("Banana", 2f, true, ScrambleMode.All)
    However, even though the characters scramble and reveal one by one, the character length jumps straight to 6 and doesn't gradually increase as I'd hope. Any ideas on how to solve this?

    Any suggestions are welcome, thanks.

    Edit: I just realized this actually worked fine in my other project so this might be a bug. Is anyone else experiencing this? I'm on Unity 2019.4.18f1 and using the latest TMPro and DOTween packages.
     
    Last edited: Jan 20, 2021
  41. _DS_1

    _DS_1

    Joined:
    Sep 6, 2016
    Posts:
    3
    Hello, I'm learning DOTween, and this code always returns true, what I'm doing wrong?

    Code (CSharp):
    1.         //if(!DOTween.IsTweening(textAnimator.target, true))
    2.         if(!t.IsPlaying())
    3.         {
    4.             Debug.Log("ASAD");
    5.             t.Play();
    6.             //textAnimator.DOShakeCharScale(0, 0.5f, 1.2f).OnComplete(() =>
    7.             //{
    8.             //    textAnimator.SetCharScale(0, Vector3.one);
    9.             //    textAnimator.SetCharScale(1, Vector3.one);
    10.             //});
    11.  
    12.         }
    13.  
    I tried autokill to true, restart, reset, the comments and nothing :/
    Thanks in advance
     
  42. polypixeluk

    polypixeluk

    Joined:
    Jul 18, 2020
    Posts:
    53
    I'm using DoTween to slide images on and off screen but the speed of animation varies quite wildly between the fast desktop and slow Android Mobile (Galaxy S8).

    Its got me thinking, maybe the tweens are linked to frame rate? Is this the case? Can anyone advise me on how to get at least relatively consistent speeds between platforms? This is the code I'm using:

    Code (CSharp):
    1. public IEnumerator TransitionIn()
    2. {
    3.  
    4.     imgPaperRect = imgPaper.GetComponent<RectTransform>();
    5.     imgPaperRect.anchoredPosition = startPos;
    6.     imgPaperRect.localRotation = Quaternion.Euler(startRot);
    7.  
    8.     imgPaperRect.DOAnchorPos(endPos, slideInTime).SetEase(Ease.OutExpo);
    9.     imgPaperRect.DORotate(endRot, rotInTime).SetEase(Ease.OutExpo);
    10.  
    11.     yield return new WaitForSeconds(pauseBeforeStamp);
    12.     StartCoroutine(StampAnim());
    13. }
    Many thanks.
    D
     
  43. sarynth

    sarynth

    Joined:
    May 16, 2017
    Posts:
    98
    As we know, the Update loop is tied to frame rate. FixedUpdate is tied to physics. But, since your goal is to move over a length of time, not a number of frames -- that shouldn't be the issue here. The first thing that comes to mind is, have you tried moving it from the left side of the screen to the right side of the screen as opposed to off-screen? I wonder if the end position is further off screen than you thought.

    You might also add a clock to your UI and show the current game time, then transition over 5 seconds, and see if the speeds are equal. They ought to be. (Of course knowing that a physically smaller device is going to look like it's traveling slower, but I presume you understand that.)
     
  44. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    358
    It is not.

    The reason you are seeing decreased performance is because you have exceeded the capabilities of your device.
    Things one can get away with on desktop are not so easily forgiven on mobile.

    Perhaps you have too many draw-calls; Too many materials; Shaders not optimized; Expensive calculations repeated needlessly in an Update loop; The new-up stutters; Non^2 textures too large for device; Garbage collection. A myriad of things. Have you run the profiler?

    Having said all that - Occam's Razor being what it is - if you see this diminished performance only with this one tween, it make sense to scrutinize there.

    With knowledge only of this snippet of code, here are some different choices you may make:

    • There is no reason to run DOTween in a coroutine. DOTween has OnComplete and SetDelay methods you should be using instead.
    • GetComponent is an expensive method to call. You may consider caching it in OnEnable. Although, this should not be an issue if you are only calling it the once or very infrequently.
    • Why are you setting the start positions? Are the game Objects not in their start positions? Perhaps put them in their start positions.
    • Why with the DoMoveAnchorPos? [rhetorical] Will DoMoveX not suffice? My guess is that this is where it all falls down. There is no need to mess with the anchors -unless you are tweening the aspect ratio of your sprites. Canvas manipulations are expensive.
    • Utilize a Sequence instead of 2 discreet tweens. << Probably won't make any difference.
    Anyway ... Impossible to know for sure without looking at your project. But rest assured, it's something you are doing, and not anything DoTween is doing ;) [ friendly jest ]

    If you do need someone to look at your project, PM me. I don't want to come across as shilling my live-help services...
     
    sarynth likes this.
  45. polypixeluk

    polypixeluk

    Joined:
    Jul 18, 2020
    Posts:
    53
    Thanks guys, that's plenty to look at. :)
     
  46. NiirB

    NiirB

    Joined:
    Jun 21, 2019
    Posts:
    13
    Hello!
    I've been using dotween in most of my projects so far, so first I just wanna save, I love this it's a great tool!

    I have two questions about the tool.
    1) How exactly do I use tweencallback methods such as OnComplete? From what I'm understanding I need to create a TweenCallback class but I can't seem to do that? I'm not the best at understanding all the programing terms so sorry if I mixed some of them up here. I would just be happy to see an example where a "onComplete" calls a function.
    2) Is there a way for me to define new eases? Unity has a AnimationCurves as components, is it possible for me to hook up an animation curve into the tweens that I'm running?

    Thanks for making the plugin, it's amazing!
     
  47. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    496
    Hello :)

    1. You don't ned to write any custom classes to use DoTween's callbacks. To use OnComplete you would do something like this:

    Code (CSharp):
    1. transform.DOMoveX(4, 1).OnComplete(MyCallback);
    Where "MyCallback" is the function you want to call. You can also use a lambda expression to write an inline function:

    Code (CSharp):
    1. transform.DOMoveX(4, 1).OnComplete(()=> { DoStuffHere; OrCallAFunction(); });
    2. To use an AnimationCurve, you use .SetEase()

    Code (CSharp):
    1. transform.DOMoveX(4, 1).SetEase(myAnimationCurve);
    This is all in the documentation, which is easy to follow and a good reference:

    http://dotween.demigiant.com/documentation.php#options
     
    NiirB and ledshok like this.
  48. Gorilla_Joes

    Gorilla_Joes

    Joined:
    Jul 22, 2015
    Posts:
    10
    Getting a strange compile errors that are baffling me.

    I installed an Asset Bundle manager thingy and since then DoozyUI is giving errors for DOTween.
    It is like it is seeing two different DOTween.dll's but I can only find the one in the Plugins folder...

    Error CS0311 The type 'DG.Tweening.Tween[]' cannot be used as type parameter 'T' in the generic type or method 'TweenExtensions.Play<T>(T)'. There is no implicit reference conversion from 'DG.Tweening.Tween[]' to 'DG.Tweening.Tween'. Assembly-CSharp C:\Development\Acumed\Assets\Doozy\Engine\UI\Animation\UIAnimator.cs
     
  49. huayanpro

    huayanpro

    Joined:
    Sep 6, 2018
    Posts:
    1
    What happens when you spam a sequence many times.
    In this example, I have this sequence that lasts 4 secs, first 2 secs it scales down and fades out, then it scales up and fades in.
    What happens to the previous sequence if the new sequence starts, will the objects receive combined effects from both sequences? Like if I spam 'A' key.

    I guess the same question goes to: What if you have multiple tweeners running on the same object on the same field, like you have 3 tweeners and they all modifies the object's transform's scale.
    What is a tweener exactly under the hood? Is it coroutine that's binded on a game object?

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using DG.Tweening;
    4.  
    5. public class SettingsUI : MonoBehaviour
    6. {
    7.     private Image image;
    8.  
    9.     void Start()
    10.     {
    11.         image = GetComponent<Image>();
    12.     }
    13.  
    14.     void Update()
    15.     {
    16.         if (Input.GetKeyDown(KeyCode.A)) {
    17.             ChangeContent();
    18.         }
    19.     }
    20.  
    21.     public void ChangeContent() {
    22.         Sequence mySequence = DOTween.Sequence();
    23.         mySequence.Append(transform.DOScale(0.7f, 2f))
    24.             .Append(transform.DOScale(1f, 2f))
    25.             .Insert(0, image.DOFade(0f, 2f))
    26.             .Insert(2f, image.DOFade(1f, 2f));
    27.     }
    28. }
     
    Last edited: Feb 3, 2021
  50. polypixeluk

    polypixeluk

    Joined:
    Jul 18, 2020
    Posts:
    53
    EDIT: Restarting Unity / VS fixed the problem


    I'm trying to use a Sequence for the first time so I can stop an active tween. But I'm getting the following error.

    Code (CSharp):
    1. UnityException: get_isPlaying is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead.
    I've tried to address it with this:

    Code (CSharp):
    1.     public Sequence mySequence;
    2.  
    3.     private void Awake()
    4.     {
    5.         mySequence = DOTween.Sequence();
    6.     }
    7.  
    8.  
    9.     private void EventProcessor()
    10.     {
    11.         objectCounter++;
    12.  
    13.         foreach (BinEvent bEvent in binEventArray)
    14.         {
    15.  
    16.             if (bEvent.spawnTrigger == objectCounter)
    17.             {
    18.                 mySequence.Append(transform.DOMove(bEvent.endPos, bEvent.travelTime));
    19.             }
    20.         }
    21.     }
    But the error remains and I'm left confused as to what I'm dong different from the examples I've seen posted elsewhere. Any pointers would be greatly appreciated!

    Thanks.
    D
     
    Last edited: Feb 4, 2021
unityunity