Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

DOTween (HOTween v2), a Unity tween engine

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

  1. sharkwithlasers

    sharkwithlasers

    Joined:
    Dec 8, 2012
    Posts:
    23
    Ahh I was not familiar with the Goto method! Thank you!

    However, I'm not sure that passing in `float t = transform.position.x / 10` would exactly work in this case, because Ease.InSine does not interpolate linearly.

    I believe that I would need to pass the current position to the inverse of Ease.InSine in order to get the proper time to start at (and I'd also need to make sure to normalize the current position when passing it to the inverse).

    I think this will work!
     
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
    Sorry yes, you are right. But there's a helper method to get the correct value.

    DOVirtual.EasedValue()

    That will return the correct value taking into account the ease.
     
    FuguFirecracker likes this.
  3. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Somebody need to make a PrebakeTween extension !
    You feel up to it, or should I do it ? ;)
     
    flashframe likes this.
  4. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
    Nice idea! I'm sure you'd do a much better job ;-)

    It'd even just be nice if this forum made it easy to sticky posts or resources. Lots of similar questions. I think the DOTween docs are pretty good, and the entire source code is available to reference, but seems like many people don't know either option exists.
     
    FuguFirecracker likes this.
  5. JohnSearle

    JohnSearle

    Joined:
    Feb 24, 2016
    Posts:
    9
    Could someone enlighten me on best practices for object disposal?

    I'm destroying a GO that makes extensive use of DOTween. I've tried using DOKill on all (sub)child transforms, and also attempted to deactivate any potential calls that might cause new tweens just prior to calling Destroy(gameObject).

    Unfortunately, I'm still receiving an generic error message that is of little help tracing the problem:
    MissingReferenceException: The object of type 'Image' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    I've also attempted to put code to kill the tweens in OnDestroy, but that doesn't help either.

    I could let safe mode swallow the errors, but I can't image that's the best practice, since a warning is being thrown.

    Thanks.
     
    Last edited: Aug 22, 2021
  6. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
    Calling DOKill should be enough.

    You can get some extra information in the [DOTween] game object that gets automatically added to your scene. If you click on "Show Playing Tweens" you might be able to find the culprit.

    Otherwise, you might want to add some debugging messages of your own to find which tween is being problematic.
     
  7. IceTrooper

    IceTrooper

    Joined:
    Jul 19, 2015
    Posts:
    37
    I was looking for exactly the same thing yesterday. I ended up checking on OnDestroy in the objects I run the tweens on to see if they have completed their actions. If not, then I call .Kill().
    Example 1:
    Code (CSharp):
    1. public class ScoreUI : MonoBehaviour
    2. {
    3.     [SerializeField] private TMP_Text scoreText;
    4.  
    5.     // ...
    6.     private int displayedScore;
    7.     private Tweener scoreTextTweener;
    8.  
    9.     // ...
    10.     private void Start()
    11.     {
    12.         scoreTextTweener = DOTween.To(x => displayedScore = (int)x, displayedScore, score.Value, 2f)
    13.             .SetEase(Ease.OutCubic)
    14.             .SetAutoKill(false)
    15.             .OnUpdate(() =>
    16.             {
    17.                 scoreText.text = displayedScore.ToString();
    18.             });
    19.     }
    20.  
    21.     // Method called when score changed.
    22.     private void ScoreChanged(int newScore)
    23.     {
    24.         scoreTextTweener.ChangeEndValue((float)score.Value, true).Restart();
    25.     }
    26.  
    27.     private void OnDestroy()
    28.     {
    29.         scoreTextTweener.Kill();
    30.     }
    31. }
    You need to know that I got some DOTween settings changed:
    1. AutoPlay - None
    2. AutoKill - enabled
    3. RecycleTweens - enabled.

    Those settings tell you:
    1. AutoPlay is disabled. It's a really nice option because I can prepare some of my Tweens in Start() and then explicitly call them when needed.
    2. AutoKill is enabled, so when the tweens complete, they are automatically killed and can be recycled because of 3. (RecycleTweens - enabled). You need to be careful with that configuration because it's said in the documentation that even a tween was killed, a reference could be not nulled, because the tween could be recycled.

    upload_2021-8-22_13-50-38.png

    In Example 1 I explicitly call SetAutoKill(false), because I know I would be reusing my tween on my own, so I don't want it to be killed when completed (and it won't be recycled by DOTween, but by me).

    Example 2:
    Code (CSharp):
    1. public class PointsUI : MonoBehaviour
    2. {
    3.     [SerializeField] private float inDuration = 0.5f;
    4.     [SerializeField] private float outDuration = 0.5f;
    5.     [SerializeField] private float intervalDuration = 0f;
    6.     [SerializeField] private float endingScale = 1.5f;
    7.     [SerializeField] private bool doPunchRotation = true;
    8.     [SerializeField, ShowIf("doPunchRotation")] private float punchPower = 60f;
    9.  
    10.     private Sequence showSequence;
    11.  
    12.     private void Start()
    13.     {
    14.         var rectTransform = GetComponent<RectTransform>();
    15.         showSequence = DOTween.Sequence()
    16.             .Append(rectTransform.DOScale(endingScale, inDuration).From(0f)).SetEase(Ease.OutCubic);
    17.         if(doPunchRotation)
    18.         {
    19.             showSequence.Join(rectTransform.DOPunchRotation(Vector3.forward * punchPower, inDuration));
    20.         }
    21.         showSequence.AppendInterval(intervalDuration)
    22.             .Append(rectTransform.DOScale(0f, outDuration)).SetEase(Ease.InCubic)
    23.             .OnComplete(() => Destroy(gameObject))
    24.             .OnKill(() => showSequence = null)
    25.             .Play();
    26.     }
    27.  
    28.     private void OnDestroy()
    29.     {
    30.         if(showSequence != null) showSequence.Kill();
    31.     }
    32. }
    Here you can see that I'm destroying my GameObject when tweening complete, but sometimes a player can restart a game or leave to the main menu even when tweens don't complete. Because of that, I added to OnKill nulling my reference (I have to do it because of the recycling option like I said before) and check inside OnDestroy if a reference is null, if not I kill my sequence.
    Of course, you can control tweens via static methods of DOTween, but they would be slower (even with intId or stringId) than simple reference.

    The things I described here are my own solution, which I came up with after thinking about it for a while. I think what you asked about 'how to properly handle tween destruction' should be described somewhere in the documentation. I have safe mode enabled but like you, I was annoyed by the errors I was getting every time.

    Anyone, correct me if I'm wrong :)
     

    Attached Files:

  8. sharkwithlasers

    sharkwithlasers

    Joined:
    Dec 8, 2012
    Posts:
    23
    Ahh, so in my particular case, I already have the starting value, but I needed to get the proper time associated with that value. With that proper time calculated, `Goto` works. I'm able to find the proper time to go to by passing the normalized starting value to the inverse of the tween (and then scaling that result by the total duration).

    Here's a hardcoded example that will toggle a looping tween's scale direction when you left click, while maintaining the easing. It yoyo's from scale 0 to 4 in four seconds (with Easing OutCubic). On the way back from 4 to 0, it uses InCubic easing:

    Code (CSharp):
    1. using DG.Tweening;
    2. using DG.Tweening;
    3. using UnityEngine;
    4. public class TweenStuff : MonoBehaviour
    5. {
    6.     private Tween curTween;
    7.     private float prevFrameScale;
    8.     void Start()
    9.     {
    10.         // starting scale 0
    11.         transform.localScale *= 0;
    12.         prevFrameScale = transform.localScale.x;
    13.         // tween from 0 -> 4 in 4 seconds with OutCubic easing
    14.         // (Yoyo's back to 0 with InCubic easing
    15.         curTween = transform
    16.             .DOScale(4, 4)
    17.             .SetEase(Ease.OutCubic)
    18.             .SetLoops(-1, LoopType.Yoyo);
    19.     }
    20.     void Update()
    21.     {
    22.         if (Input.GetMouseButtonDown(0))
    23.         {
    24.             // currently scaling up, so let's scale down
    25.             if (transform.localScale.x > prevFrameScale)
    26.             {
    27.                 var prevScale = transform.localScale.x;
    28.                 curTween.Kill();
    29.                 transform.localScale = Vector3.one * 4;
    30.                 curTween = transform
    31.                     .DOScale(0, 4)
    32.                     .SetEase(Ease.InCubic)
    33.                     .SetLoops(-1, LoopType.Yoyo);
    34.                 var normalizedVal = (4 - prevScale) / 4;
    35.                 // multiply by total duration (4 seconds)
    36.                 var timeToGoTo = InverseInCubic(normalizedVal) * 4;
    37.                 curTween.Goto(timeToGoTo, true);
    38.             }
    39.             // currently scaling down, so let's scale up!
    40.             else
    41.             {
    42.                 var prevScale = transform.localScale.x;
    43.                 curTween.Kill();
    44.                 transform.localScale = Vector3.zero;
    45.                 curTween = transform
    46.                     .DOScale(4, 4)
    47.                     .SetEase(Ease.OutCubic)
    48.                     .SetLoops(-1, LoopType.Yoyo);
    49.                 var normalizedVal = prevScale / 4;
    50.                 // multiply by total duration (4 seconds)
    51.                 var timeToGoTo = InverseOutCubic(normalizedVal) * 4;
    52.                 curTween.Goto(timeToGoTo, true);
    53.             }
    54.         }
    55.         prevFrameScale = transform.localScale.x;
    56.     }
    57.     // should return the proper T (normalized)
    58.     private float InverseOutCubic(float normalizedVal)
    59.     {
    60.         return 1 - Mathf.Pow(1 - normalizedVal, 1f / 3f);
    61.     }
    62.     // should return the proper T (normalized)
    63.     private float InverseInCubic(float normalizedVal)
    64.     {
    65.         return Mathf.Pow(normalizedVal, 1f / 3f);
    66.     }
    67. }
    68.  
     
  9. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Is it the one GameObject with multiple tweens upon it or nested GameObjects with tweens upon tweens ?
    The procedure is: kill the tweensdestroy the object(s); Nothing more complicated than that.

    If you have multiple tweens associated with a GameObject, it's incumbent upon yourself to keep track of these tweens and kill them at the appropriate time. A use-case for SetId() perhaps?

    Myself, I'd push them there tweens into a Stack<tween> and foreach those buggers to death ;)
     
  10. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    Question. I have a bunch of
    GameObject
    s being moved with the
    DOMove
    method on their transforms. I need fine control over how these objects move so I'm almost exclusively moving them between two points with
    DOMove
    , as opposed to something like the physics system.

    However, I also need to know how fast -- and in which direction -- the tweened objects are going at any time. Since I'm directly controlling the position with tweens, these objects don't have a physical velocity to speak of. But I still need this information. Does DOTween have an API that'll help me figure out the velocity of a position-tweened object at the current moment in time, or should I just do the calculus myself? And if I need to do the math myself...how would I do so? It's been a while.
     
    Last edited: Aug 28, 2021
  11. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
    Velocity = Displacement / Time

    I don't believe there's anything built in for this, but you can use the OnUpdate() callback to calculate the displacement of the transform and divide by Time.deltaTime (or Time.fixedDeltaTime is you are using UpdateType.Fixed).
     
    JesseSTG likes this.
  12. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    Thank you. Is there a way to get the previous value of the tween, per chance?
     
  13. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
    I don't think so - I'd store that as a local variable
     
    JesseSTG likes this.
  14. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    307
    Anyone know if there's a way to ease in-out between each spline node, rather than for the whole spline?

    I know this can be worked around by making a few smaller paths and lining them up as if they were one large path. But it would be convenient if there were some way to do this within a single path.

    E.g. imagine panning a camera to several destinations, and then returning to the player. If each node represents a destination, you'd probably want easing between each node rather than for the whole path.
     
    curbol likes this.
  15. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Code (CSharp):
    1.    
    2. [SerializeField] private float Distance;
    3. [SerializeField] private float Duration;
    4.  
    5.         void Start()
    6.         {
    7.             var goSpeedRacer = transform.DOMoveX(Distance, Duration)
    8.                 .SetDelay(2);
    9.            
    10.             goSpeedRacer.OnUpdate(() => Debug.Log(GetSpeed(goSpeedRacer)));
    11.         }
    12.  
    13.  
    14.         private float GetSpeed<T>(TweenerCore<Vector3, Vector3, T> tweenerCore) where T : struct, IPlugOptions
    15.         {
    16.             return  Vector3.Distance(tweenerCore.startValue, transform.position) / tweenerCore.position;
    17.         }
     
    JesseSTG likes this.
  16. The_MrX_

    The_MrX_

    Joined:
    Aug 25, 2019
    Posts:
    12
    Greetings I made a card system using dotween via the DotweenPath component.

    Basically, I use the tween component in DotweenPath to calculate a new set of points for a DOPath() from the current position of the card to the new position somewhere on the path which represents the player's hand.

    The word Portion means the location on the path between 0 and 1.

    Code (CSharp):
    1.  private Vector3[] GetPoints(int numOfPoints, float destinationPortion)
    2.       {
    3.          var portionPerPoint = destinationPortion/ numOfPoints;
    4.          var points = new List<Vector3>();
    5.          for (int i = 0; i < numOfPoints + 1; i++)
    6.          {
    7.             points.Add(GetPointFromPortion(portionPerPoint * i));
    8.          }
    9.          return points.ToArray();
    10.       }
    11.  
    12.       private Vector3 GetPointFromPortion(float portion)
    13.       {
    14.          return _doTweenPath.tween.PathGetPoint(portion);
    15.       }
    Now unfortunately the DOTweenPath component has really bad controls for easily adjust the Path in the editor itself so I want to make my own version.

    But I can't seem to get a tween from a "Path" instance. It only gives the option to set the wps and wpsLengths

    https://i.imgur.com/KG3B2rU.png

    And doing a DOPath() on a transform with the path gives me a TweenerCore, which I can't seem to get a tween from either. Am I missing something or did the recent update change something that makes it impossible to get a Tween from a path now?

    Code (CSharp):
    1. TweenerCore<Vector3, Path, PathOptions>
     
    Last edited: Sep 6, 2021
  17. NeoKuro

    NeoKuro

    Joined:
    Jan 30, 2015
    Posts:
    20
    Is it possible to edit the DOTween(Path)'s inspector?

    I want to add some useful tools, right now just a basic button which will do something. But I've tried writing a "[CustomEditor(typeof(DOTweenPath))]", I've tried overriding the 3 DOTween Editors ("DOTweenSettingsInspector", "DOTweenComponentInspector", and "DOTweenUtilityWindow") but whilst it compiles, my simple button doesn't appear.

    Is it possible to just add a button to the top or bottom of the editor?
     
  18. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
    I'm not sure if you can @FuguFirecracker might,

    BUT what you can definitely do is make a new component that takes the DoTweenPath as a parameter, and create a custom inspector for that component.
     
    FuguFirecracker likes this.
  19. patrickjansendesign

    patrickjansendesign

    Joined:
    Jan 21, 2020
    Posts:
    48
    So I spend hours trying to get a constant speed for DOmove to work but so far no luck. I have a scene with 4 cubes which I put in gameobject[] "positions". Then I make my camera holder gameobject move from 1 to 2 to 3 to 4

    Code (CSharp):
    1.         Sequence S = DOTween.Sequence();
    2.         for(int k = 0; k < positions.Length; k++){
    3.             S
    4.                 .Append(camholder.transform.DOMove(positions[k].transform.position, 5f))
    5.             ;
    6.         }
    7.         S
    8.             .SetEase(Ease.Linear)
    9.         ;
    but I can't get it to move with a non-accelerating/decelerating constant speed
    I tried Ease.Unset, no other in/out will obviously solve this. I tried using .OnComplete(() => donext()) where the donext function creates a whole new tween for every move between points, also to no avail

    HOW DO I GET A CONSTANT SPEED?
    heeeelp
     
  20. olleyOop

    olleyOop

    Joined:
    Nov 29, 2013
    Posts:
    9
    Hello,

    how do I get the following information from a tween e.g. assigned to a transform:
    easing, start value, end value, what exactly is getting changed ( e.g. Rotation or position ).

    I only found the possibility to get the information listed in the docu under "Getting data from tweens"

    Did I miss something?
     
  21. gabry90

    gabry90

    Joined:
    Dec 16, 2015
    Posts:
    29
    Hi all, how to pass some metadata object through Sequence?
     
  22. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
    Don't forget that both the Sequence AND the Tween have easing. So you need to set both to Linear.
     
    FuguFirecracker likes this.
  23. iS_mAv

    iS_mAv

    Joined:
    Jan 8, 2016
    Posts:
    1
    Hi, could any of you help me with the issue I have in this game I published? https://marco-valerio.itch.io/test
    I use DoShakeScale in order to give some game feel to my game, and even though in Unity it behaves just fine, it looks rubbish on my web build on itch.io! Can anyone help me with this?
     
  24. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Your SetEase is in the wrong place.
    Code (CSharp):
    1.  
    2.        Sequence S = DOTween.Sequence();
    3.  
    4.         for(int k = 0; k < positions.Length; k++)
    5.          {
    6.             S.Append(camholder.transform.DOMove(positions[k].transform.position, 5f)
    7.               .SetEase(Ease.Linear)); // IT GOES RIGHT HERE
    8.           }
     
  25. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Metadata?
    Uh.... Can you write some pseudocode to show what you're trying to do?
     
  26. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    You need to specify what the differences are between the platforms.
    Expected behaviour vs actual behaviour and all that ...
     
  27. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Use any respectable IDE to look at the autocomplete when you type a '.' directly after the name of your Tween.
    The lowercase fields are the data fields. You may retrieve their values or set them to null or whatever.
    Now y'all know the difference between OnComplete and onComplete ;)
     
  28. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
  29. gabry90

    gabry90

    Joined:
    Dec 16, 2015
    Posts:
    29
    i want to pass some data through tween inside sequence. I use some extensions method that return tween for custom animation but i don't understand how to pass data through tweens inside sequence
     
  30. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Still not enough information. What data?

    Metadata is "data that provides information about other data". In other words, it is "data about data
    Dotween has no specific methodologies for passing metadata through tweens.
    You need to write that method that takes that parameter and sends that data OnUpdate or OnComplete or
    OnValuesChanged or whenever you want to retrieve it.

    Do you mean ACTUAL data, such as speed, position, time, path, etc ?
    Yeah ... You need to write a method that sends that data OnUpdate or OnComplete or OnValuesChanged or ... see answer above.
     
  31. olleyOop

    olleyOop

    Joined:
    Nov 29, 2013
    Posts:
    9
    Thanks for the hint. But I already did that. That's why I'm asking if there is someone who can tell me how to get those data from a tween: "easing, start value, end value, what exactly is getting changed ( e.g. Rotation or position )."
    Because those are the ones I need but couldn't find so far.
    If it is not possible to get those data does anyone know why?

    As an example let's assume there is this tween:
    Code (CSharp):
    1. Tween tweenly = transform.DOMoveX(10, 3).SetEase(Ease.InCubic).SetDelay(.1f);
    Can I get the information from above out of tweenly?
     
    Last edited: Sep 14, 2021
  32. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Easing is only ever gonna be what you tell it to be ... Or the default.
    I can think of no scenario why you would need this information to be calculated.
    Let me know how shortsighted I am if you need this.

    You need to cast as TweenerCore
    Code (CSharp):
    1.  
    2.   Debug.Log(((TweenerCore<Vector3, Vector3, VectorOptions>) tweenly).startValue.x);
    3.   Debug.Log(((TweenerCore<Vector3, Vector3, VectorOptions>) tweenly).endValue.x);
    4.  
    Again, I don't know why you wouldn't already know this. It's changing what you tell it to change.
    Or if you for got that you told it to DoMoveX ... Use the getter
    Code (CSharp):
    1.  
    2. Debug.Log(((TweenerCore<Vector3, Vector3, VectorOptions>) tweenly).getter.Method);
    3.  
    If you explain your use-case, maybe I can steer you in a better direction.
     
  33. olleyOop

    olleyOop

    Joined:
    Nov 29, 2013
    Posts:
    9
    Hey,

    first, thanks for your explanations.
    Let's assume we use Unity not for games at all but for high fidelity UI prototypes and I want to add a layer on top of one of those prototypes to achieve something like the recipes from Protopie ( especially at 1:50 ).
    My thought was, that all the information I need should already be in the tweens ( all animations are handled by them ) and I was a bit baffled that I can't get out the information I've put in.

    I also tried your suggestion to cast the tween as TweenerCore and found 2 problems here:
    1. the start value is 0 as long as the tween hasn't been started but I want to know the real start value
    2. I must know the type to cast the tween. The example doesn't work anymore if the tween changes the alpha value of a CanvasGroup

    I hope you understand my issue better now.
     
  34. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Then you require another layer of abstraction to encapsulate the data you require.
    Stick your tween in an object, struct, or tuple. Every scrap of information you want is available or known.

    Yeah ... You can't get information that isn't there yet. But as luck would have it, the starting value is always know beforehand ... by you. You just need to retrieve it.

    It's an example. I give you the theory => You apply it to your situation.

    Here's one last hint on this topic:

    Untitled.png

    In conclusion, just do a Flyweight Pattern with the data you need exposed as properties.
     
    Last edited: Sep 15, 2021
  35. olleyOop

    olleyOop

    Joined:
    Nov 29, 2013
    Posts:
    9
    Thanks again for your help.
    Yeah, that was my feeling as well after I took a look on DoTween to see if my needs are "already built-in".
    I have to build something around to get what I need. Do you see any chance, those things will be included in future releases?
     
  36. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    _tmp_php1xna7z_magic8ball1.jpg
     
  37. Abdo023

    Abdo023

    Joined:
    Dec 18, 2017
    Posts:
    64
    I'm getting error:
    Delegate 'TweenCallback' does not take 1 arguments


    Here is the code:
    Code (CSharp):
    1. transform.DOMove(targetPos, 1).SetEase(Ease.Linear).onComplete(ChangeState);
    2.  
    It's very similar to this line of code in the documentation:
    Code (CSharp):
    1. transform.DOMoveX(45, 1).SetDelay(2).SetEase(Ease.OutQuad).OnComplete(MyCallback);
     
  38. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
  39. Abdo023

    Abdo023

    Joined:
    Dec 18, 2017
    Posts:
    64
  40. fubukibanana

    fubukibanana

    Joined:
    Aug 29, 2021
    Posts:
    4
    Code (CSharp):
    1. Tween tween = transform.DOScale(new Vector3(1.5f, 1.5f, 1.5f), 0.4f);
    I call this function in my project.
    When I run my project, it work fine.
    However, Visual Studio report error CS0246 "Not found namespase Vector2".
    How can I remove error?
     
  41. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    809
  42. LazyEti

    LazyEti

    Joined:
    Sep 10, 2017
    Posts:
    7
    Hello!
    I'm trying to tween characters of a TMP text but I'm having an issue when using .DOScaleChar()

    I'd like to make the characters appear (scale from zero to 1) but even when setting the tween to .From(), the characters will start from a scale value of 1 :

    Code (CSharp):
    1. currentTypeSequence.Insert (timeOffset+1, _tweener.DOScaleChar (i, 0, 1).From().SetEase (Ease.OutBack, 5));
    I also tried to set the scale of characters manually before the sequence using .SetCharScale() but it doesn't seem to have any effect (the text keeps it's original size until the letter is updated by a tween)

    Code (CSharp):
    1.  
    2.      for (int i = 0; i < _tweener.textInfo.characterCount; ++i)
    3.         {
    4.             _tweener.SetCharScale (i, Vector3.one*5);
    5.         }
    6.         _tweener.Refresh ();
    7.  
    I assume I might be doing something wrong since there's no examples on how to use this functionality
    Does anyone know how to deal with this / if this is a bug ?
     
  43. Epiplon

    Epiplon

    Joined:
    Jun 17, 2013
    Posts:
    52
    I'm using DOTween Path to create a moving platform in my game but I wanted the platform to stop and wait a few seconds in each waypoint. Is that possible?
     
  44. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Use the for loop to set the Transform component scale directly.
     
  45. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    .
    .SetDelay() with recursion.
     
  46. LazyEti

    LazyEti

    Joined:
    Sep 10, 2017
    Posts:
    7
    Hey, thanks for the message but like I mentioned, I need to scale up individual text mesh pro characters and not a game object.
    Unfortunately the characters scale is not refreshed after using .SetCharScale()
    (The characters keep their original scale until they start to be tweened)

    Also, I tried to forceMeshUpdate on the text after the for loop but that didn't work either
     
  47. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Oh right you are ...
    Here is how you set character scale and then tween those characters
    This code works. If your code doesn't, you'll need to post the complete method(s) so I can see where it all falls down.

    Code (CSharp):
    1.  
    2. public class CharTweenGlean : MonoBehaviour
    3.     {
    4.       [SerializeField]  private TMP_Text _tmpText;
    5.       void Start()
    6.         {
    7.             var tmpAnimator = new DOTweenTMPAnimator(_tmpText);
    8.          
    9.             for (var i = 0; i < tmpAnimator.textInfo.characterCount; i++)
    10.             {
    11.                 tmpAnimator.SetCharScale(i, Vector3.zero);              
    12.                 tmpAnimator.DOScaleChar(i, Vector3.one, 3.3f).SetDelay(i * 0.2f).SetEase(Ease.OutBack);
    13.             }
    14.      
    15.         }
     
    Last edited: Sep 25, 2021
  48. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    Hello. I want to switch to doTween from current tween package I'm using. Had couple of questions. If tweens are paused/resumed/reset do they generate any memory allocations in these operations. Any info you can provide is appreciated.
     
    Last edited: Sep 27, 2021
  49. Stickeyd

    Stickeyd

    Joined:
    Mar 26, 2017
    Posts:
    174
    Hey. How can I make the DOShakePosition function not fade out slowly? It's currently like it has easeOut(thought it doesn't). There seems to be a bool "fadeOut" when I call that function, but if I set it to false, it doesn't help.

    I just don't want it to slow down closer to an end. https://gyazo.com/973fd43048e96aa8aa38087209e5321a
     
  50. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Yes it does.
    There are 2 bool arguments, snapping and fadeout.
    Possible you've only the one bool assigned. you either need to assign values to both bool arguments or use named arguments

    Assign the following monobehaviour to 2 cubes in your scene. Set one to fadeOut, leave the other as false.
    Observe the difference.

    Do note the named argument.

    Code (CSharp):
    1.  
    2.  
    3. using DG.Tweening;
    4. using UnityEngine;
    5.  
    6. namespace FuguFirecracker
    7. {
    8.     public class ShakyFace : MonoBehaviour
    9.     {
    10.         public bool DoFadeOut;
    11.        
    12.      
    13.         void Start()
    14.         {
    15.             transform.DOShakePosition(5f, .5f, 25, 22f, fadeOut:DoFadeOut);
    16.         }
    17.  
    18.    
    19.     }
    20. }
    21.