Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

DOTween (HOTween v2), a Unity tween engine

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

  1. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    151
    I haven't used DOTween for a while and am having brain freeze, could someone tell me how to infinitely ping pong between two rotations, I was hoping LoopType.Yoyo would be the answer but that either just pings without ponging or goes screwy....

    Code (CSharp):
    1. if (thisAxis == Axis.z) {
    2.             startRotate = this.transform.localEulerAngles;
    3.             startRotate.z -= angle;
    4.  
    5.             endRotate = this.transform.localEulerAngles;
    6.             endRotate.z += angle;
    7.         }
    8.  
    9.         //this.transform.localEulerAngles = startRotate;
    10.  
    11.         SetupPlayTween ();
    12.     }
    13.      
    14.  
    15.     void SetupPlayTween(){
    16.         mySequence = DOTween.Sequence();
    17.         mySequence.Append (this.transform.DOLocalRotate (endRotate, duration / 2.0f, RotateMode.Fast));
    18.         mySequence.Append (this.transform.DOLocalRotate (startRotate, duration / 2.0f, RotateMode.Fast));
    19.         mySequence.SetLoops (-1, LoopType.Yoyo);
    20.     }
     
  2. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    151
    This seems to work:
    Code (CSharp):
    1.     void PlayT1(){
    2.         Tween t1 = this.transform.DOLocalRotate (endRotate, duration / 2.0f, RotateMode.Fast).SetLoops (1, LoopType.Yoyo).OnComplete (PlayT2);
    3.     }
    4.     void PlayT2(){
    5.         Tween t2 = this.transform.DOLocalRotate (startRotate, duration / 2.0f, RotateMode.Fast).SetLoops (1, LoopType.Yoyo).OnComplete (PlayT1);
    6.    
    7.     }
     
  3. mikatu

    mikatu

    Joined:
    Aug 3, 2015
    Posts:
    28
    You should be able do it with just one tween like this
    Code (CSharp):
    1.  
    2. transform.eulerAngles = startRotate;
    3. this.transform.DOLocalRotate (endRotate, duration / 2.0f, RotateMode.Fast).SetLoops (-1, LoopType.Yoyo);
     
  4. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @woshihuo12 The eases are the classic ones created by Robert Penner (except the Flash ones I made myself), so you can check them all here.

    @ortin Ah that makes sense :) And yes, a custom exception is considered like an "object destroyed" one, and that is the only case I don't throw warnings (because it would be overkill).

    @wxxhrt What @mikatu said is totally right. Also, pay attention when using RotateMode.Fast, since it will just travel using the shortest direction, while maybe you want RotateMode.FastBeyond360 (which uses "true" rotations).
     
  5. asdas

    asdas

    Joined:
    Aug 30, 2012
    Posts:
    2
    I've purchased the pro version and it doesn't work for Unity 5.4b18.
    It gives me this error: Assets/Demigiant/DOTweenPro/DOTweenAnimation.cs(58,16): error CS0246: The type or namespace name `ScrambleMode' could not be found. Are you missing a using directive or an assembly reference?

    Can you update the asset store pro version package?
     
  6. McSwan

    McSwan

    Joined:
    Nov 21, 2013
    Posts:
    85
    Hi,

    I am using dottween for an Augmented Reality example of Dogs going around a race course. The dog paths need to move locally, as the entire track and dogs move based on the position of the augmented reality paper marker.

    Can I Make a path that uses localMove? It works with dot tween animation with localMove, but that seems to only do 1 tween and I need to manually enter in the values.

    upload_2016-6-8_10-38-37.png
     
  7. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    851
    I'm using the Unity 5.4 and DOTween Pro and I get this warning:

    Is there a beta version or something that I can use to get rid of it?

    Fantastic work on the plugin btw. By FAR the best one around. ;)
     
  8. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @asdas Hi. That error is not related to DOTween or Unity's version, but to some other namespace-less plugin you have in your project. If you check your project, you'll find some class that is named ScrambleMode and that is not part of DOTween. That would normally be ok, except in cases where said class is not inside a namespace, in which case it won't allow any other ScrambleMode class (like DOTween's) to exist. When you find it, please let me know: all Unity assets should use namespaces, and I will warn the creator about it.
    P.S. On a secondary note, also check that you don't have duplicate DOTween folders. When you import the Pro it already contains a DOTween folder, so if you had one already you should delete it.

    @McSwan Hi. Sure, at runtime you can use DOLocalPath, or if you're using the DOTweenPath component you just have to check the "Local Movement" checkbox.

    @luispedrofonseca Hi Luis, thanks for the nice words! If you're not already registered on DOTween Pro's private download area, follow these instructions. Then you can grab the latest version which is Unity 5.4 compatible (I will update the Asset Store one when 5.4 is out of beta).
    P.S. Actually, since that issue only involves DOTween's core, you can also just download the latest one here.
     
  9. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    151
    @Izitmee @mikatu Thanks! Thats works and I get the desired behaviour using SetEase.
     
  10. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    151
    I'm rusty with classes. I was hoping the code below would continuously run a separate sequence on each blendshape in a skinnedMeshRenderer. The code gets to the AdjustBlendShape function but only runs that function once.

    I tried breaking the class into its own file and deriving from monobehaviour, I tried adding the class as a component, could someone point out where I'm going wrong? Thanks.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using DG.Tweening;
    4. using System.Collections.Generic;
    5.  
    6.  
    7. public class script_004_RandomBlendshapePlayer : MonoBehaviour {
    8.  
    9.     public Vector2 lerpDurationVec;
    10.     public Vector2 waitDurationVec;
    11.     public List<class_BlendShapePlayer> myClassList = new List<class_BlendShapePlayer>();
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.         BuildClassList ();
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.    
    21.     }
    22.  
    23.     void BuildClassList(){
    24.         SkinnedMeshRenderer smr = this.gameObject.GetComponent<SkinnedMeshRenderer>();
    25.         Mesh mesh = smr.sharedMesh;
    26.         int count = mesh.blendShapeCount;
    27.         Debug.Log (count);
    28.  
    29.         for (int i = 0; i < count; i++){
    30.             //class_BlendShapePlayer myClass = this.gameObject.AddComponent ("class_BlendShapePlayer") as class_BlendShapePlayer;
    31.             class_BlendShapePlayer myClass = new class_BlendShapePlayer();
    32.             myClass.lerpDurationVec = lerpDurationVec;
    33.             myClass.waitDurationVec = waitDurationVec;
    34.             myClass.blendShape = i;
    35.             myClass.Start();
    36.             myClassList.Add(myClass);
    37.         }
    38.     }
    39. }
    40.  
    41.  
    42. public class class_BlendShapePlayer : script_004_RandomBlendshapePlayer{
    43.  
    44.     public Vector2 lerpDurationVec;
    45.     public Vector2 waitDurationVec;
    46.     public int blendShape;
    47.  
    48.     float currentPosition = 0.0f;
    49.     float nextPosition = 0.0f;
    50.     float lerpDuration;
    51.     float waitDuration;
    52.  
    53.     Sequence mySequence;
    54.  
    55.     public void Start(){
    56.         currentPosition = nextPosition;
    57.         nextPosition = Random.Range (0.0f, 100.0f);
    58.         lerpDuration = Random.Range (lerpDurationVec.x, lerpDurationVec.y);
    59.         waitDuration = Random.Range (waitDurationVec.x, waitDurationVec.y);
    60.  
    61.         PlaySequence ();
    62.     }
    63.  
    64.     void PlaySequence(){
    65.         mySequence.Kill (false);
    66.         mySequence = DOTween.Sequence();
    67.         mySequence.Append(DOTween.To(AdjustBlendShape, currentPosition, nextPosition, lerpDuration));
    68.         mySequence.AppendInterval(waitDuration).OnComplete(Start);
    69.         Debug.Log ("made_PlaySequence");
    70.         mySequence.PlayForward ();
    71.     }
    72.  
    73.     public void AdjustBlendShape( float f){
    74.         Debug.Log ("made_AdjustBlendShape");
    75.         Debug.Log (f);
    76.         SkinnedMeshRenderer smr = this.gameObject.GetComponent<SkinnedMeshRenderer>();
    77.         smr.SetBlendShapeWeight (blendShape, f);
    78.     }
    79. }
    80.  
     
  11. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @wxxhrt

    Hey, first of all you cant instantiate a monobehaviour with new, it just doesnt work that way.

    Code (CSharp):
    1. class_BlendShapePlayer myClass = new class_BlendShapePlayer();
    What you want to do is use AddComponent, still, everything you are trying to do is very weird. You are calling "Start" manually, but Unity will call start before you do, I am guessing the sequence is playing on a 0 duration because of this, and since it has an OnComplete, it is killing the sequence you currently have.

    You dont really need a Monobehaviour, just create a class that you can instantiate, pass the SkinnedMeshRenderer, the information about the blendShape and call a sequence from it. It should be a lot simpler, hope this helps.
     
    Izitmee likes this.
  12. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    151
    Thanks @JakeTBear I've got it working as a Monobehaviour using AddComponent but its a bit inelegant, the inspector gets cluttered up.

    I thought instantiating a class was what I had been doing in the code above, it's getting late here but I'll look at this tomorrow with fresh eyes.

    Thanks for your help.
     
  13. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @wxxhrt Yeah its just you shouldnt need to have it as a MonoBehaviour, if it is a class (without inheriting anything) you can use "New" and a constructor to initialize all the information you need, best of luck! and have a good night :)
     
  14. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    342
    Any ideas about solving this?

    Plugin 'DOTween43.dll' is used from several locations:
    Assets/DOTween/DOTween43.dll would be copied to <PluginPath>/DOTween43.dll
    Assets/Demigiant/DOTween/DOTween43.dll would be copied to <PluginPath>/DOTween43.dll
    Plugin 'DOTween46.dll' is used from several locations:
    Assets/Demigiant/DOTween/DOTween46.dll would be copied to <PluginPath>/DOTween46.dll
    Assets/DOTween/DOTween46.dll would be copied to <PluginPath>/DOTween46.dll
    Plugin 'DOTween.dll' is used from several locations:
    Assets/Demigiant/DOTween/DOTween.dll would be copied to <PluginPath>/DOTween.dll
    Assets/DOTween/DOTween.dll would be copied to <PluginPath>/DOTween.dll
    Please fix plugin settings and try again.

    UnityEditor.Modules.DefaultPluginImporterExtension:CheckFileCollisions(String)
    UnityEditorInternal.PluginsHelper:CheckFileCollisions(BuildTarget) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Plugins/PluginsHelper.cs:25)
    UnityEditor.HostView:OnGUI()

    This error doesn't affect play but when building it also throws an additional error:
    Plugins colliding with each other.

    I have DOTween pro and in one scene I have an DOTween behavior specified.

    Thanks
     
  15. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    342
    I deleted the package Assets/DOTween/
    It built fine.

    Thanks

     
  16. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @gegagome Yup, DOTween Pro already comes with DOTween, so if you have DOTween already you should delete it before (or after) importing the Pro, to avoid double versions of the same libraries.
     
  17. mikatu

    mikatu

    Joined:
    Aug 3, 2015
    Posts:
    28
    Run into some WebGL bugs:

    DOShakePosition has strange behaviour where it jumps to a random position after the animation finishes. It happens only when you build for WebGL-build (not in the editor or any other type build). It occurs with the following parameters:

    rectTransform.DOShakePosition(8, 10, 5);


    Also, doing the following does't work in WebGL and often causes the game to freeze.

    DOVirtual.DelayedCall(2, tryMe);
    void tryMe(bool p = false) { Debug.Log(p); }

    Somehow related to the use of optional parameters.

    Using v.1.1.300 HC with Unity 5.3.4.

    Edit:
    The Callback-error seems like it could be a Unity-bug. Testing is just so painfully slow because none of this occurs in the editor.
    Strangely enough, in the editor the code above results in expected behaviour printing out "false", whereas
    System.Action callback = tryMe;
    tryMe(); // Prints "true"???

    Edit2:
    Ok, it may be that the DOShakePosition-bug only occurs in Chrome. At least it worked fine Safari. Not sure how much this has to do with DOTween after all. Except for that, everything seems to be running fine and I am using DOTween quite heavily in my game.
     
    Last edited: Jun 16, 2016
  18. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    NEW DOTWEEN UPDATE v1.1.310
    • BUGFIX: Finally fixed bug which was captured but still generated an "Error in RemoveActiveTween..." warning
    Finally I managed to reproduce this and it's fixed, wohoooo!



    @mikatu That is weird! Can you try this latest version and let me know how it behaves? I think this fix might be connected to it. Also, for your second issue, an Action doesn't work correctly with optional parameters, so yes, you'll have to include it, like this:
    Code (csharp):
    1. DOVirtual.DelayedCall(2, ()=>tryMe(false));
     
  19. mikatu

    mikatu

    Joined:
    Aug 3, 2015
    Posts:
    28
    Yeah, the callback-error turned out to be a bug in Unity and they confirmed it has been fixed in the latest beta-release.
    Regarding the DOShakePosition-bug, the latest version did not fix it. It seems to happen only in Chrome.
     
  20. Arany666

    Arany666

    Joined:
    Jun 25, 2015
    Posts:
    11
    Hi. Hope someone can help me. I'm using DOtween with Plamaker and with Smart pool. My problem is that if the tween is not finishing before despawn, if I respawn the gameobject the tween is continueing where it was despawned, not where I respawned it. I'm an visual artist not a coder so pls be gently. :)

    Pls help dont want to use ITween, but I'll if I have to! :)

    If This can be solved I'll purchase the Pro ver and buy a beer to the developer!

    Thanks
     
  21. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @Arany666

    You are going to need to kill the tween manually when the game object gets deactivated. I havent done this myself, since I tend to cache everything, but you can potentially do this:

    Code (CSharp):
    1. void OnDisable()
    2. {
    3.            DOTween.Kill(gameObject);
    4. }
    Just add that code into a component thats attached to your object. Hope this helps :)
     
    Izitmee likes this.
  22. Arany666

    Arany666

    Joined:
    Jun 25, 2015
    Posts:
    11
    Thank you. I'll try it. You deserved your beer, call me any time you If you find yourself in Hungary. :)
     
  23. pat68

    pat68

    Joined:
    Dec 15, 2013
    Posts:
    34
    Dear all,
    @Izitmee
    first thank you for this great tool!

    Perhaps someone can help me with this.
    I am trying to rotate a 2D rigidbody around in 90° steps. Every touch should rotate in 90°.

    In principal it is working like this:
    Code (CSharp):
    1. public void OnTap()
    2. {
    3.     float angle = object.Angle;
    4.  
    5.     angle += 90.0f;
    6.  
    7.     rb2D.DORotate (angle, 1.0f);
    8.  
    9.     if (angle == 360)
    10.         angle = 0;
    11.  
    12.     object.Angle = angle;
    13. }
    This working until 270°. At 0° again, the sprite is rotating back in the other direction from 270 to 0 instead of a single step to the 360° (0°).

    I can continue to increase the angle above 360° which works, but I don't want to get to type boundaries.

    Greetings
    Pat
     
  24. Brity

    Brity

    Joined:
    Feb 27, 2016
    Posts:
    116
    I cant believe im actually having to post this question on something so simple but here goes.

    well i have my two Dotween animations on my object.

    and two references.
    DOTweenAnimation StartAnim, SecondAnim;

    I've dragged my first animation (StartAnim) which moves the local Y to 10 relative
    I've dragged my Second animation (SecondAnim) which moves the local x to 10 relative

    StartAnim.DOPlay();
    Well it should play that specific animation and not the second right. nope.. it plays the SecondAnim and ignores StartAnim

    Autoplay is switched off on both and i don't have a dotween manager.

    also i have to use : StartAnim.DOPlayById("1"); and add an id but why do i need to add an id if I've made a direct reference to it?

    also you documentation says :
    myTween.Rewind();
    but it forces me to
    myTween.DORewind();

    does docs need updating?

    Also when i using a pooling system this pretty much messes everything up.
    is this supposed to work with other pooling assets?
    have you tested it with other pooling assets?
     
    Last edited: Jun 19, 2016
  25. john-essy

    john-essy

    Joined:
    Apr 17, 2011
    Posts:
    464
    Hey there,

    I am currently using this for my menus but i have hit a little stumble. When the user clicks on a button while the tweens have not finished, I need it to finish the current tweens and then start my next ones when the previous are done.

    I need to know how do i access a tween on an object with multiple tween objects? Say i have one tween that scales and one that fades, how do i directly access and manipulate the say fades tween?

    Cheers
     
    Last edited: Jun 21, 2016
  26. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    342
    Hello there

    How are you doing?

    I have a vertical layout group that consists of the letters in the alphabet.

    Users can do either of these two options:
    - vertically scroll letters
    - use the center letter. Depending on whether they drag the letter left/right it sends a message to the following method by passing a letter index (a List) so a letter is moved and centered in the vertical layout group.

    Code (CSharp):
    1. public void LetterInterval (int value) {
    2.         float offset = value * LetterHeight;
    3.         float offsetMin = _rectHeight + offset;
    4.         float offsetMax = offset;
    5.  
    6.         //        Debug.Log(offsetMin);
    7.         //        Debug.Log(offsetMax);
    8.  
    9.         DOTween.To(() => _rectForVerticalLayoutGroup.offsetMin, x => _rectForVerticalLayoutGroup.offsetMin = x, new Vector2(0f, offsetMin), _CENTERING_TIME).SetEase(Ease.InOutCubic);
    10.         DOTween.To(() => _rectForVerticalLayoutGroup.offsetMax, x => _rectForVerticalLayoutGroup.offsetMax = x, new Vector2(0f, offsetMax), _CENTERING_TIME).SetEase(Ease.InOutCubic);
    11.     }
    PROBLEM is that moving the vertical layout group kind of spikes the physics 2d in the profile, but more importantly going from A back to Z causes a serious expensive on an iPhone 6 Plus. It jumps from 23% to 50%. See the video:

    https://www.dropbox.com/s/q8rdh3zann5tal4/video of tweening.mov?dl=0

    My solution is to store the Sequence, but I am unsure how you store a lambda, given the final value is not always known.

    Hope that makes sense.

    Thanks
    German
     
  27. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    418
    @Izitmee Did you remove the "fadeOut" parameter from DOShakePosition? It's in the docs, but doesn't seem to be available.

    Also, is there an easy way to set up a looping tween that uses a random value on each loop?

    Thanks!


    UPDATE: I upgraded to the latest DOTween Pro version (0.9.530) and can now access the fadeOut parameter. Maybe it was just missing from 0.9.470?
     
    Last edited: Jun 26, 2016
  28. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    284
    LoopType.Incremetal ?
     
    Izitmee likes this.
  29. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    284
    Recursion!
    And lambdas.
    Gotta have lambdas.
    Code (CSharp):
    1.  
    2. private float _floatyMcFloaterton;
    3.  
    4. protected void Start()
    5.         {
    6.             PickIt();
    7.         }
    8.  
    9.  private void PickIt()
    10.         {
    11.             var newFloat = Random.Range(0f, 42f);
    12.             AssignIt(newFloat);
    13.         }
    14.  
    15.  private void AssignIt(float newFloat)
    16.         {
    17.             DOTween.To(() => _floatyMcFloaterton, x => _floatyMcFloaterton = x, newFloat, 20)
    18.                 .OnComplete(() =>
    19.                 {
    20.                     _floatyMcFloaterton = newFloat;
    21.                     PickIt();
    22.                 });
    23.         }
     
    Izitmee likes this.
  30. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    284
    But how does it play?
    Are there actual issues on the actual device?
    If it's only a matter of the profiler belching out numbers you don't like... ignore it.
    If there are actual real world ramifications, then you've got some refactoring to do.

    Sorry to say, but the Unity UI implementation is HEAVY.
    Although, not as heavy as it used to be... There have been considerable performance improvements.
    But it wasn't designed to build an entire game with... As tempting as that may be.

    See Here for issue with ScrollRect
    And Here for why not to use physics with the UI
    Or you can just Google : Unity UI Heavy

    I am making some assumptions here, because you do specifically mention 2D Physics and the use of the VerticalLayoutGroup UI element.

    So to make a short story even longer
    Unity UI does do a lot of work for you, but it comes at a cost.
    If you've got performance issues, you need to switch out to sprites.
     
    Izitmee likes this.
  31. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    418
    Thanks @FuguFirecracker, really awesome of you to write out that example for me!

    One question. How performant is this method if I were to assign it to a lot of objects? I'm planning to use it for groups of 2D vines & leaves on trees to create random animated movement.

    Do you think the randomness in DOShake uses a similar method under the hood?

    Thanks again!
     
  32. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    284
    Don't know until you profile it.
    And unnecessary speculative optimizations are the root of all evil ;)

    There's a whole bunch of ways to resolve randomness with tweens.
    You could always inline it as well...

    Code (CSharp):
    1.  _transform.DOLocalMove(new Vector3(Random.Range(-2, 2), Random.Range(-2, 2), Random.Range(-2, 2)), 3f);
    possibly the most performant -with the caveat of slight increased memory overhead- would be to define a min and max value defining how much movement you want and then build an array of vectors in the Awake() method using Random.Range.

    Code (CSharp):
    1.      
    2. private Transform _transform;
    3.  
    4. private  float _min = -1.8f;
    5. private float _max = 1.8f;
    6. private int _vectorCount = 10;
    7. private Vector3[] _shakeVectors;
    8.  
    9.         protected void Awake()
    10.         {
    11.             _shakeVectors = new Vector3[_vectorCount];
    12.  
    13.             for (var i = 0; i < _shakeVectors.Length; i++)
    14.             {
    15.                 _shakeVectors[i] = new Vector3(Random.Range(_min, _max), Random.Range(_min, _max)); // zero  Z is implied
    16.             }
    17.         }
    18.  
    19.         private void ShakeIt()
    20.         {
    21.             _transform.DOLocalMove(_shakeVectors[Random.Range(0, _shakeVectors.Length)], 1.3f)
    22.                 .SetLoops(-1, LoopType.Yoyo);
    23.         }
    Actually, the MOST performant would be to push those vectors into a Stack<> or Queue<> and iterate through that collection thereby eliminating the runtime Random method.

    Code (CSharp):
    1.  private Queue<Vector3> _vQ = new Queue<Vector3>();
    2.  
    3.         protected void Awake()
    4.         {
    5.             _shakeVectors = new Vector3[_vectorCount];
    6.  
    7.             for (var i = 0; i < _shakeVectors.Length; i++)
    8.             {
    9.                 _shakeVectors[i] = new Vector3(Random.Range(_min, _max), Random.Range(_min, _max)); // zero  Z is implied
    10.                 _vQ.Enqueue(_shakeVectors[i]);
    11.             }
    12.         }
    13.  
    14.         private void ShakeIt(Transform t)
    15.         {
    16.             _vQ.Enqueue(_vQ.Peek()); // put the first on the end;
    17.             t.DOLocalMove(_vQ.Dequeue(), 1.3f)
    18.                 .SetLoops(-1, LoopType.Yoyo);
    19.         }
    And you don't need 100 random vectors for 100 moving objects.
    10 should be plenty to make everything look random.
    Try changing the tween duration slightly. I would suggest building an array of primes... ;)

    Or I could be totally wrong.
    Who knows.
    Try it and see.
     
    Last edited: Jun 26, 2016
    flashframe and Izitmee like this.
  33. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    418
    But soooooo tempting! It brings out the OCD in me.

    Thanks again for taking the time to help and for the code samples! These are great suggestions. For now I will try your original solution using Random.Range() and see how it performs. :)
     
  34. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    Thanks again to the very masterful @FuguFirecracker and @JakeTBear for the help! And woah, Fugu, great stuff there!

    @john essy Ahoy! If you're talking about runtime tweens, you can just store a reference to them. If you mean tweens created via the visual DOTween Pro editor instead, you can grab a list of them via myDOTweenAnimation.GetTweens(), which will return a reference to all tweens created in the same order (top-down) as you see them. Otherwise, you can also use IDs and static DOTween methods (like DOTween.Complete(myId), which will complete all tweens with the given ID).

    @gegagome Hey! You can't have dynamic values inside a Sequence (if I understood correctly what you meant). And moving many object inside Unity's UI is expensive due to the UI's kinda-heaviness I'm afraid, and has nothing to do with the tween itself, so a Sequence won't help.
    On a secondary note, to add a generic lambda tween to a Sequence, you just append/insert/join it as a regular shortcut. For example:
    Code (csharp):
    1. Sequence s = DOTween.Sequence()
    2.    .Append(DOTween.To(()=> _rectForVerticalLayoutGroup.offsetMin, x => _rectForVerticalLayoutGroup.offsetMin= x, newVector2(0f, offsetMin), _CENTERING_TIME).SetEase(Ease.InOutCubic))
    @flashframe What the magnificent @FuguFirecracker said! About DOShake's fadeOut, it's a new feature, so it's present only since a couple releases ago.
     
  35. FatIgor

    FatIgor

    Joined:
    Sep 13, 2015
    Posts:
    29
    Can I attach a Sequence to a selected object? I can see how to create a sequence with an object specified in it, but can I create a sequence and then apply it to an object? Like this for example, then run it against an object selected at runtime.

    Code (CSharp):
    1.         selectedSequence=DOTween.Sequence();
    2.         selectedSequence.Append(transform.DORotate(new Vector3(0,0,-180),1,DG.Tweening.RotateMode.WorldAxisAdd));
    3.         selectedSequence.Join(transform.DOScale(new Vector3(1.3f,1.3f,1f),1f));
    4.  
     
  36. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @FatIgor Hi! You mean change that "transform" property any time? Sorry but no, once a Sequence is created it becomes like a fixed animation.
     
  37. tabor

    tabor

    Joined:
    Nov 29, 2011
    Posts:
    42
    Could someone help me with a bit of code please?

    I want to be able to select an easing type from a drop down menu in the inspector.

    So that I do something like:
    .SetEase(mySelectedEase);

    I just cant figure it out....
    Thanks for reading!
     
  38. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @tabor Ahoy! You mean you just want to create a public ease variable in a MonoBehaviour, so that Unity's Inspector shows a combobox with all possible DOTween's eases to choose from? If so, just write the public variable like this:
    Code (csharp):
    1. public DG.Tweening.Ease ease;
    (or without the "DG.Tweening" if you imported the namespace already)
     
  39. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    @Izitmee Is there a way to add a RectTransform Dotween Animation for a recttransform's min & max anchors to the DOTween Animation script? Currently, I see we can change the left/right/bottom/top, but it'd be nice to change the anchor values.
     
  40. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @Ben-BearFish Hi Ben! I can't access Unity right now, but later I'll see if I can add this :)
     
    Ben-BearFish likes this.
  41. Doireth

    Doireth

    Joined:
    Jul 3, 2012
    Posts:
    11
    Is there any way to provide a callback to tweens inside of a sequence. I assigned the callback to "OnStart" but that only works once with the sequence. If the sequence is looped, the callback is not called.

    Alternatively, is there a way for a callback to run every time a tween begins?

    Thanks
     
  42. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @Doireth Hi, OnStart is only called when a tween starts the very first time, but you can just use InsertCallback ;)
     
  43. Doireth

    Doireth

    Joined:
    Jul 3, 2012
    Posts:
    11
    Yea, that's what I ended up using. The only problem with that method is that you must work out the timing manually, which can be a problem in certain situations. Thanks.
     
  44. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    409
    Hi! I'm new to Dotween and still a noob programmer. I was wondering if it could be possible to use Dotween to interpolate variables in Adventure creator? (for meters/bars) The problem I have, is that AC uses a special method to update Global variables from the "outside", i.e.:

    AC.GlobalVariables.SetIntegerValue(GvarId, NewValue);

    I'm unsure how I would go about using Dotween to interpolate the values. And I'm also unsure how variable updating works "internally" in AC, so I can't really tell you if there's a better way to access the data...

    Anyways, do you think there is a way I could affect them using Dotween, or do I have no other choice but to do it manually in the Update function?
     
  45. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    418
    DOTween has a callback called OnUpdate, which gets fired every time the tween updates - no surprise there ;-)
    You could use that to update your Global Variable.

    Untested example:

    Code (CSharp):
    1.  
    2. int gVarID = 12; //for example
    3. float myFloat = 0;
    4.  
    5.  
    6. // Tween myFloat to 100 in 1 second
    7. DOTween.To(()=> myFloat, x=> myFloat = x, 100, 1).OnUpdate(()=> UpdateGlobalVariable(gVarID, myFloat));
    8.  
    9.  
    10. void UpdateGlobalVariable(int id, float f)
    11. {
    12.     AC.GlobalVariables.SetIntegerValue(id, f);
    13. }
    14.  
     
    Izitmee and Alverik like this.
  46. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    409
    Hey, thanks! I'll give it a try when I get back :)
     
  47. fusecore

    fusecore

    Joined:
    Oct 3, 2013
    Posts:
    15
    Hi! I'm working with DoTween in my project and I'm having a few issues, perhaps you could help me?

    Issue 1:
    When a tween is being executed and I change scene, there's a huge list of errors claiming the missing transform, or material or whatever was being tweened is missing.

    MissingReferenceException: The object of type 'Transform' 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.

    Attempted:
    - OnLevelWasLoaded: DOTween.KillAll();
    No luck.
    - OnLevelWasLoaded: DestroyImmediate(GameObject.Find("[DOTween]"));
    No more tweens. Even after calling DOTween.Init();

    Issue 2:
    DOTween eats errors from other scripts. A simple index out of range in any script is "silently handled" by DOTween while it has nothing to do with it.
    Turning off Safe Mode in preferences displays the errors as originating from the TweenManager


    IndexOutOfRangeException: Array index is out of range.
    DG.Tweening.Core.TweenManager.RemoveActiveTween (DG.Tweening.Tween t) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:833)
    DG.Tweening.Core.TweenManager.Update (UpdateType updateType, Single deltaTime, Single independentTime) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:401)
    DG.Tweening.Core.DOTweenComponent.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:50)
    (I don't have a D drive)
     
  48. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,233
    @flashframe Hello! Thank you very much for helping out :)

    @fusecore Hi!

    Issue 1
    That will happen if you have safe mode disabled. Using DOTween.KillAll will also work, but you have to call it BEFORE the current level stuff is destroyed (meaning when you start loading the new level), not AFTER (as OnLevelWasLoaded does).

    Issue 2
    I assume you're using the Asset Store version, which is a little out of date. Grab the latest one here (just unzip the files in the DOTween folder, and re-run DOTween's setup) which solves that issue.
     
  49. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    409
    Hi, I'm currently implementing the code, haven't tested it yet, but still, I have a question. I have some situations where I need to decrease an amount instead of increasing it, how would you change the code to reflect a decrease instead of an increase? I'm sorry for asking, but Lambda expressions feel like Chinese to me...

    Edit: Do I just need the "To" value to be negative?
    Edit 2: Also, how would I make sure the increase and decrease never overshoot the min/max values? (like 0-1 for floats and 0HP-XHP?). Is there a way to break out of the increase/decrease in case it reaches the min/max? (should I just modify the Functions Dotween is going to be calling?)

    EDIT: Never mind, I feel like an idiot. Seeing as it's a From:To Function that just means I can say e.g.: 100 to 0, right? I wasn't expecting to be able to do both operations so easily, with just one command... but well, I'm not much of a programmer, lol
     
    Last edited: Jul 14, 2016
  50. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    151
    I'm tweening objects along a path, when they reach the end they loop back to the start. I'd like this behaviour to happen when playing the tween in reverse, is it possible? Here's what I've tried:

    Code (CSharp):
    1.  
    2. t = prefabOb.DOPath (waypoints, pathDuration, pathType)
    3.                 .SetOptions (closeWaypointLoop)
    4.                 .SetLookAt (0f)
    5.                 .OnRewind(()=>HasFullyRewound(t))
    6.                 .SetEase (Ease.Linear)
    7.                 .SetLoops (-1);
    8.          
    9.             if (playBackwards) {
    10.                 t.PlayBackwards();
    11.             }
    12.  
    13. void HasFullyRewound(Tween t){
    14.         t.fullPosition = pathDuration;
    15.         t.PlayBackwards();
    16.     }
     
unityunity