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

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    358
    It was because my timescale was 0 duh... lol.
    rect.DOShakeAnchorPos(1).SetUpdate(true); works great.
     
  2. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    358
    Can you set a tween once and then just reuse it like so? Because calling .Play() isn't doing anything for me.

    Code (CSharp):
    1.  
    2.     private Tweener inventoryShakeTweener;
    3.  
    4.     private void Start()
    5.     {
    6.                 inventoryShakeTweener = CanvasManager.instance.inventoryGameobject.GetComponent<RectTransform>().DOShakeAnchorPos(1).SetUpdate(true);
    7.     }
    8.  
    9. public void SomeMethod()
    10. {
    11.                     if (!inventoryShakeTweener.IsPlaying())
    12.                     {
    13.                         inventoryShakeTweener.Play();
    14.                     }
    15. }
    16.  
     
  3. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    811
    You either have to disable AutoKill in the settings or set AutoKill to false when you set up the tween.

    Code (CSharp):
    1. inventoryShakeTweener = CanvasManager.instance.inventoryGameobject.GetComponent<RectTransform>().DOShakeAnchorPos(1).SetUpdate(true).SetAutoKill(false);
    2.  
    Code (CSharp):
    1. private void OnDestroy()
    2. {
    3.      inventoryShakeTweener.Kill();
    4. }
     
    Razputin likes this.
  4. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    358
    Thank you, actually already tried with AutoKill false though as it says to turn it off in the docs if you want to use play.

    I found that using .Restart() will give me the behavior I was expecting from .Play()
     
    Last edited: Mar 13, 2024
    flashframe likes this.
  5. AdamBlaszczyk

    AdamBlaszczyk

    Joined:
    Oct 8, 2018
    Posts:
    11
    Hi, I have a problem. I can't access DOAnchorPos method. When I try to use rect.DOAnchorPos(newPosition, duration), I get:
    'RectTransform' does not contain a definition for 'DOAnchorPos' and no accessible extension method 'DOAnchorPos' accepting a first argument of type 'RectTransform' could be found (are you missing a using directive or an assembly reference?)

    My modules panel looks like this.

    upload_2024-3-15_19-32-59.png
     
  6. AdamBlaszczyk

    AdamBlaszczyk

    Joined:
    Oct 8, 2018
    Posts:
    11
    OK, found the solution. I needed to generate assembly definitions from utility panel and add them to my project's asmdef.
     
  7. ZivVek

    ZivVek

    Joined:
    Apr 21, 2021
    Posts:
    3
    I am using DOTween Pro version 1.0.381.
    lets say I have a progress bar which goes from 0 to 1 and want a progress bar to fill by 0.3f per second (that is 3 seconds to fill it). I want it to keep looping and to call a method every time it reaches 1.
    So I have done something like this:

    private void StartFoodBar()
    {
    var tween = DOVirtual.Float(0, 1, 3f, v => _foodBar.value = v).SetLoops(-1, LoopType.Restart)
    .SetSpeedBased(true).SetEase(Ease.Linear).OnStepComplete(
    () => { Debug.Log("food bar is full. do something"); });
    }

    For some reason, the debug.log is shown twice on every step complete.
    I've tried using OnComplete but that also didn't work.

    Why does it call the callback method twice on OnStepComplete?
     
  8. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    811
    First thing I'd check is to confirm you are not accidentally calling StartFoodBar more than once? You don't perform any check against doing that. You can give tweens an ID, which you could add to the debug to confirm this.
     
  9. osmanzort

    osmanzort

    Joined:
    May 22, 2019
    Posts:
    21
    Edit2: Found out the issue was about setting timescale to 0 and then exiting to the main menu so it wasn't really related to DOTween.

    I'm using DOTween to fade out a black image in the Main Menu and it plays when you first launch the game (properly). When you go into the game by selecting a level, Main Menu is replaced by the levelUI and all the tweens are killed. If you go back to the main menu after that, the black image is back without any transition and even if the DOTween component shows like the tween is playing, it just stays at alpha=1 and never goes down. What might be causing this behaviour?

    This is the code I'm using for the transition:

    Code (CSharp):
    1.     private void Awake()
    2.     {
    3.         DOTween.KillAll();
    4.         transition.SetActive(false);
    5.         transitionCanvasGroup = transition.GetComponent<CanvasGroup>();
    6.     }
    7.  
    8.  
    9.     private void Start()
    10.     {
    11.         FadeIn(transitionDuration);
    12.     }
    13.  
    14.     public void FadeIn(float duration)
    15.     {
    16.         Debug.Log("Fading in");
    17.         transition.SetActive(true);
    18.         transitionCanvasGroup.alpha = 1;
    19.         transitionCanvasGroup.DOFade(0, duration).OnComplete(()=> { transition.SetActive(false); });
    20.     }
    Edit: I also have another fade effect playing on a loop in the main menu and that one is also stuck after going back. It should be about something related to DOTween's caching but I'm not sure. Doesn't it reset all the tweens when you unload/reload a scene?
     
    Last edited: Apr 2, 2024
  10. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    811
    You can set Tweens to be time scale independent using:

    Code (CSharp):
    1. .SetUpdate(UpdateType.Normal, true);
     
    osmanzort likes this.
  11. Game-Dragon

    Game-Dragon

    Joined:
    Nov 16, 2012
    Posts:
    37
    I'm having a little trouble getting DOLookAt to work on a single axis. I have a camera rig that's parented to a first person character controller. The character controller rotates in the Y axis, and the child camera rig rotates only on the X axis.

    I'd like the camera rig to look at a target but only change the X axis. I've tried using AxisConstraint.X, but this doesn't seem to work.
    Code (CSharp):
    1. rig.DOLookAt(target, 1f, AxisConstraint.X);
     
  12. anilcool

    anilcool

    Joined:
    Mar 8, 2020
    Posts:
    7
    I am trying to move a gameObject along the defined bezier path, which I think the DOTween plugin will let me do.

    However, I also want to make the object jump a short distance and rotate along the bezier curve, Can this tool allow me to do that? Can somebody post an example before I purchase the DOTween plugin?
     
  13. halfmanhalfdog

    halfmanhalfdog

    Joined:
    Dec 19, 2021
    Posts:
    3
    I think the DOJump method is kind of similar to a bezier path?
     
  14. AdamBlaszczyk

    AdamBlaszczyk

    Joined:
    Oct 8, 2018
    Posts:
    11
    Other way to do it is to have two objects, parent and child. You move parent along curve and move child to modify the path, like jumping shaking or rotating.
     
  15. ZivVek

    ZivVek

    Joined:
    Apr 21, 2021
    Posts:
    3
    That is correct. Only once.
     
  16. Warcmus

    Warcmus

    Joined:
    Dec 4, 2020
    Posts:
    2
    Hi everyone,

    I'm encountering an issue with implementing a custom DoJump function in DoTweenPro version 1.0.381.
    What I am essentially trying to do is to perform a DoJump in the Z-axis instead of the default Y-axis. Here's what I've tried and the problem I'm facing:

    1. Issue: Despite creating a custom function named DoJumpZ in the DoTweenModulePhysics.cs file, the function is not recognized when trying to call DoJumpZ in my script.
    2. Observation: I noticed that the DoJump function is being called from DG.Tweening.ShortcutExtensions (RMB/Go To Definition), a seemingly generated file located in C:\Users(User)\AppData\Local\Temp\MetadataAsSource. This file seems to be inaccessible for modifications.
    3. Attempts to Resolve:
      • I tried deleting the generated file, updating, and reimporting DoTween, but to no avail.
      • I also added M:DG.Tweening.ShortcutExtensions.DOJumpZ (etc.) to the DoTween.XML file, but the custom function still isn't recognized.
      • Additionally, I attempted removing and re-adding the physics module without success.
    Has anyone encountered a similar issue or found a workaround? I'm open to suggestions, such as rotating the tween itself to act on the Z-axis instead of the Y - but am unsure if this can be done.

    Any help or insights would be greatly appreciated!

    Thanks in advance!
     
  17. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    488
    I would like to use the Path tool to have a smooth flight path of my drone. BUT, I would like to make the waypoints Random. How would I go about doing that?
     
  18. Denzill7

    Denzill7

    Joined:
    May 25, 2020
    Posts:
    1
    Hi,
    After getting feedback from a tester, I've noticed my DOMove animations won't properly scale if set to a higher resolution (i.e. 4K instead of 1080p). Is there an easy way to fix this in code? Is there a way to use anchors to ensure movement to a proper screen position? Would appreciate some pointers.
     
  19. Warcmus

    Warcmus

    Joined:
    Dec 4, 2020
    Posts:
    2
    Hi there,

    I wanted to provide an update on the issue I posted earlier.

    Unfortunately, I wasn't able to successfully update the shortcut-functions as initially planned. However, I did manage to find a workaround to make the function work by modifying the physics-script and attaching a rigidbody to my object. However, I found the motion to be quite unnatural, with the object moving fast in the beginning and very slow towards the end.

    To address this issue, I ended up writing my own function that creates a jumping path to the end destination. Instead of using the built-in DoJump function, I utilized the path tween to smoothly move the object between my waypoints.

    I think we'd need a bit more information about your particular needs.
    If only slight randomness is desired you could first make a list of positions forming a direct line from start to finish, and then introduce some randomness by iterating over each point, adding/subtracting/multiplying the x/y/z-coordinates within a certain range.

    Cheers.
     
  20. nicolafern

    nicolafern

    Joined:
    Nov 20, 2020
    Posts:
    3
    Hi, I'm looking at using the path animations to animate some actions in my VR app. I have a sample set up complete, however I have a small problem. The animation set up has a rotatable parent, like a lazy susan/rotating disc. This way the user can grab the disc and move it around, to view the animation and objects from different angles.

    The objects follow the parent on rotation before the path animation plays, but after it has animated, the object that was animated with the path remains stationary. If I rotate the parent manually during runtime in the scene view, then it moves correctly, including when subsequently moved by the player. I've made a short video to illustrate the problem.



    The object is not changing parent and interestingly, when I'm turning the turntable and the animated object is *not* moving, the rotation and position of the animated object *is* changing in the inspector transform component. Is this something that can be fixed? I've looked through the docs and don't see anything, and google threw up a similar issue on the Github issues log from January.

    I'm using Unity 2022.3.18f1 and DOTween Pro 1.0.381
     
    Last edited: Apr 28, 2024
  21. sapsari

    sapsari

    Joined:
    May 30, 2013
    Posts:
    14
    What is the best way to sync two identical tweens with different targets?

    Code (CSharp):
    1.  
    2. //Background is SpriteRenderer
    3. seq = DOTween.Sequence();
    4. seq.Append(Background.DOColor(Color.red, 2)).
    5.     Append(Background.DOColor(Color.white, 3)).
    6.     SetLoops(-1);
    7. seq.Play();
    Lets say I have two SpriteRenderers, and I attach the tween above to both of them. But their creation times are different and I want them to show the same color at the same time.

    I believe a tween can't have multiple targets. Or tweens doesn't have Clone/Duplicate methods.

    I tried to use GoTo and ManualUpdate methods as below but there is a 10-20 ms delay between them
    Code (CSharp):
    1. seq.Goto(Time.realtimeSinceStartup, true);
    Code (CSharp):
    1. seq.ManualUpdate(elapsed, elapsed);
    Should I bind a tween's OnUpdate callback method and set other SpriteRenderer.Color properties manually in that update method? Is there a simpler solution?
     
  22. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    811
    You could use the generic method of tweening to tween a single Color variable that both SpriteRenders use as their color value.

    Code (CSharp):
    1.  
    2. Color myColor = Color.white;
    3. DOTween.To(()=> myColor, x=> myColor = x, Color.red, 1f);
     
    sapsari likes this.
  23. sswita21

    sswita21

    Joined:
    Mar 9, 2022
    Posts:
    1
    support for unity 6?