Search Unity

HOTween: a fast and powerful Unity tween engine

Discussion in 'Assets and Asset Store' started by Demigiant, Jan 7, 2012.

  1. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi Spikeh: EaseType.Linear is exactly what you're looking for, which applies no ease at all :)
     
  2. Spikeh

    Spikeh

    Joined:
    Jun 7, 2013
    Posts:
    24
    Damn it... I was looking under the InOut properties. That'll teach me for relying on Resharper's intellisense ;) Thank you!
     
  3. stations

    stations

    Joined:
    Aug 8, 2012
    Posts:
    6
    How can i replicate this with HOTween? It rotates the object only on the z axis. I tried with the plugins but couldn't get it to work.

    myMesh.transform.Rotate(new Vector3(0, 0, 1), 20f, Space.Self);
     
  4. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Code (csharp):
    1.  
    2. HOTween.To(myTransform, duration, new TweenParms()
    3.    .Prop("localPosition", new Vector3(0, 0, 1)
    4. );
    5.  
     
  5. stations

    stations

    Joined:
    Aug 8, 2012
    Posts:
    6
    I don't understand how this will rotate the object 20 degrees along z? Where does the 20 go?
     
  6. stations

    stations

    Joined:
    Aug 8, 2012
    Posts:
    6
    Also is it possible to loop forever?
     
  7. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Oh, sorry, here is the same code to move 20 degrees and loop back and forward infinitely
    Code (csharp):
    1.  
    2. HOTween.To(myTransform, duration, new TweenParms()
    3.    .Prop("localPosition", new Vector3(0, 0, 20)
    4.    .Loops(-1, LoopType.Yoyo)
    5. );
    6.  
    You can find additional documentation here
     
  8. stations

    stations

    Joined:
    Aug 8, 2012
    Posts:
    6
    I'm sorry to keep harping on this but you gave code to modify position. I need to rotate my object along one axis only. If I change localPosition to localRotation the object is rotated along all axis. The transform.Rotate() method in unity does this. How can I replicate please? :)

    Thank you.
     
  9. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Agh I'm sorry, I'm in a rush this weekend and wrote that wrongly. Replace "localPosition" with "localRotation" in that piece of code and it's done :)
     
  10. stations

    stations

    Joined:
    Aug 8, 2012
    Posts:
    6
    No worries. I love this great tool you've provided so thank you. I had mentioned that I did already try to replace localPosition with localRotation and it rotates on all axis and not just Z. Here is my code

    TweenParms parms = new TweenParms();
    parms.Prop("localRotation", new Vector3(0,0,20));
    parms.Loops(-1, LoopType.Yoyo);
    HOTween.To(middleTextMesh.transform, 1, parms );

    but this code works perfectly

    middleTextMesh.transform.Rotate(new Vector3(0, 0, 1), 20f, Space.Self);

    Thank you for your help. :)
     
  11. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Ok I'm superstupid today, I apologize :p I'm making the video for the final release of my latest game, and it's completely burning my brains.

    Here it is. I stopped to read calmly and I even tested it, so this time it should be ok:
    Code (csharp):
    1.  
    2. HOTween.To(middleTextMesh.transform, 1, new TweenParms()
    3.   .Prop("localRotation", new Vector3(0, 0, 20), true)
    4.   .Loops(-1, LoopType.Yoyo)
    5. );
    6.  
    The "true" added after the Vector3 will make your rotation relative, so the other axis-es won't be touched.
     
  12. stations

    stations

    Joined:
    Aug 8, 2012
    Posts:
    6
    worked perfectly, thank you sir. I read the docs but somehow missed the true for relative.
     
  13. dmutt

    dmutt

    Joined:
    Jun 3, 2013
    Posts:
    17
    Hey...it's been a while. I've been pretty busy. Just to let you know...I got rid of the "HOTween Visual Editor," and it got rid of the line 117 error. I don't use the "HOTween Visual Editor" anyway so it did not affect my project. That line 117 error must be linked to the visual editor. I even did your demos with it, and it produced the same error warning. Other than that, your product works great. Thanks for everything.
     
  14. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @stations: whew! I got it! I was starting to think that question was cursed and I would get it wrong again :D

    @dmutt: thanks for letting me know. It still feels like a mystery since I know people developing stuff with the Visual Editor without any line 117 error. Anyway, I'll wait and see if someone else has some feedback about it.
     
  15. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    New HOTween Update v1.1.860

    - Various memory allocation optimizations
    - Implemented Andrew Kingdom's mod (OnPluginUpdated callback, waypointIndex exposed in PlugVector3Path)
    - Added string id and int id overload to IsTweening static method
    - OnPlay is now called also when starting
    - OnPause is now called also when tween is complete or rewinded
    - Added KeepDisabled/KeepEnabled method parameters to Tweeners and Sequences (more info here)

    As usual, while it's uploaded to the Asset Store, you can get it from the website.
     
  16. mrKaizen

    mrKaizen

    Joined:
    Feb 14, 2011
    Posts:
    139
    Hi man, I updated HOTween from 1.1.780 but I have a bug with the reverse method: the tween that had played won't reverse until I call another Play function after the Reverse.

    Some code - Tween creation:

    Code (csharp):
    1. chara1In = HOTween.To(pageChara01Tr, .5f,new TweenParms().Prop("localPosition", posCenter).AutoKill(false));
    2. chara1In.Pause();
    first call - and it moves:
    Code (csharp):
    1. chara1In.Restart();
    When I press BACK, the tween should reverse, as usual:
    Code (csharp):
    1. if(pageChara01Tr.localPosition == posCenter){
    2.     chara1In.Reverse();
    3.    
    4. }else
    5.     {...}
    But won't.
    I add
    Code (csharp):
    1.     chara1In.Play();
    after the Reverse:
    Code (csharp):
    1. if(pageChara01Tr.localPosition == posCenter){
    2.     chara1In.Reverse();
    3.     chara1In.Play();
    4.    
    5. }else {...}
    and it runs as it should.
    Did I miss something?
    TKS in advance.
     
  17. mrKaizen

    mrKaizen

    Joined:
    Feb 14, 2011
    Posts:
    139
    Hi Again!
    I tried the code on your example (the three cubes > _DemoScene ):

    .on the v.1.1.780 it works without the Play();
    .on the v1.1.860 it works only with the the Play() after the Reverse();

    ...maybe it's a new approach? :)

    Tks in advance for you time, @Izitmee!
     
  18. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Ouch, no, that's a bug *_* Actually, I suppose you're calling Reverse after the tween has finished. Before, it worked because the tween wasn't considered "paused" at completion. Now it doesn't because it is, and Reverse respects the play state. So, it's a "new approach", but since it breaks previous implementations I'll definitely consider it a bug and make sure that Reverse automatically plays the tween even if paused :)

    Gonna work on it tomorrow, or maybe this evening, if I have the time.
     
  19. mrKaizen

    mrKaizen

    Joined:
    Feb 14, 2011
    Posts:
    139
    Tks Daniele, good to know..
    In any case, no pressure for me -_^
     
  20. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    I started putting my hands on it, and I realized that actually the new current behaviour is more correct:
    - If the tween is complete, it's considered paused and thus if you Reverse it you will need to also call Play (or you could just directly call PlayBackwards)
    - If the tween is playing, and thus not paused, Reverse works as before

    So I'm torn. On one side the current behaviour is better. On the other it might break some previous code. But since it's a little piece of code, maybe it's ok. What you think? Options:
    a) I just force Reverse to also call Play (but this means that even if you paused the tween manually, it will start playing again, while previously it didn't)
    b) I add a parameter to Reverse which, if set to true, will also force-play (but that will be set to false by default)
    c) It's ok as it is
     
  21. mrKaizen

    mrKaizen

    Joined:
    Feb 14, 2011
    Posts:
    139
    Uff.. hard question. :\
    Honestly in my mind write Rewind() and then Play() is not so elegant and I don't like it.
    For me OPTION B is the right one..
    But until now I didn't realize that there is also PlayBackwards -_- even if I read the docs many times. :|
    Uhm, didn't understand really the difference but after I use it it fixed a little bug I had :D
    Uhm... because right now I don't understand the difference, Rewind+Play could be the right choice - I mean with what you have in mind.
    ;)

    (Btw, until now nobody seems to use it :p )
     
  22. sharkyx

    sharkyx

    Joined:
    Mar 20, 2013
    Posts:
    8
    Thanks for HOTween, I love it!

    Is there a way to tween a Color32 property currently?
     
  23. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Glad you like it sharkyx. Uhm, no, I didn't think to implement a Color32 plugin. Will do that!
     
  24. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hey sharkyx, I just added a Color32 plugin to the core plugins of HOTween :) Here you go (will update on the asset store later).

    NOTE: you don't have to use the PlugColor32 plugin: just tween a Color32 property and it will kick in automatically
     
  25. sharkyx

    sharkyx

    Joined:
    Mar 20, 2013
    Posts:
    8
    Wow, awesome! Thanks! :)
     
  26. Unnumeric

    Unnumeric

    Joined:
    Jun 3, 2013
    Posts:
    9
    Hi! I've been using HOTween (which is awesome), but I was wondering one thing - when does hotween update during the frame?

    I have some functions I want to run after hotween is done moving things around but before another part of my update() step.has run. I'm using script execution order to control my scripts within the frame.
     
  27. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi Unnumeric!

    HOTween.cs is actually a MonoBehaviour, which contains all the update routines (using regular MonoBehaviour Update, FixedUpdate, and a coroutine for the TimeScaleIndependentUpdate). You can either drag it into the Script Execution Order panel and set it to update BEFORE everything else (you can reach HOTween.cs even if it's in a DLL, by simply clicking the HOTween DLL arrow to open its inner hierarchy), or set your script to update AFTER everything else.
     
  28. Unnumeric

    Unnumeric

    Joined:
    Jun 3, 2013
    Posts:
    9
    Thanks for the quick response, that solves my problem perfectly! Did not know you could open up DLLs, that's super handy.
     
  29. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Indeed superhandy (even on personal projects, I always prefer to work with DLLs, and they're pretty seamless). Now if only classes were ordered alphabetically inside DLLs it would be fantastic :p
     
  30. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi Izitmee,

    I'm having a weird problem with HoTween. All my tweens work perfectly except this one. I thought maybe other code was running while doing the Tween but that isn't the case. Here's my code:

    Code (csharp):
    1.  
    2. public void NNext()
    3.     {
    4.         this.gameObject.GetComponent<PictureScreenManager>().ResetPanel();
    5.         if(!string.IsNullOrEmpty(Name))
    6.         {
    7.             DM.setName(Name);
    8.             PhotoScreen.SetActive(true);
    9.             this.gameObject.GetComponent<PictureScreenManager>().setDefaultButton(gender);
    10.             HOTween.To(PhotoScreen.transform, 0.5f, "localPosition", new Vector3(0,0,0), false);
    11.             HOTween.To(NameScreen.transform, 0.5f, new TweenParms().Prop("localPosition", new Vector3(-2800, 0 ,0), false).OnComplete(TurnOff));
    12.         }
    13.         else
    14.         {
    15.             Popup.SetActive(true);
    16.             PopupNameLabel.SetActive(true);
    17.             HOTween.To(Popup.transform, 0.5f, "localScale", new Vector3(1,1,1), false);
    18.         }
    19.     }
    20.  
    All this code executes perfectly except this line:
    Code (csharp):
    1.  
    2. HOTween.To(NameScreen.transform, 0.5f, new TweenParms().Prop("localPosition", new Vector3(-2800, 0 ,0), false).OnComplete(TurnOff));
    3.  
    The weird thing is, it runs the tweens but the position of the screen resets itself while tweening. The TurnOff function runs though because when the tween finishes it turns off the NameScreen.
     
  31. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi Tripwire,

    I tried to reproduce your issue but everything works nice on my side, and I can't see anything wrong in the piece of code you submitted. Can you try to reproduce it in a sample project and send it to me, so I can check it out?
     
  32. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi Izitmee,

    I forgot to mention the code runs perfectly in the Unity Editor. But when i'm building it and running the code on Android it doesn't work :(
     
  33. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Superweird *_* I use HOTween massively on various Android projects, and that's a thing I can rely upon. Maybe something else is interfering? Like physics influencing the transform? Maybe the interference can be noted only with the lower FPS of some Android machine? Or at lower resolutions? Can you tell me exactly what happens step by step?
     
  34. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi Izitmee,

    I'll send you a video of what happends in the Unity3D Editor and what happends on the Android device. Weird thing is though that when I use iTween or set the panel transform it also doesn't work on the Android device. But it does work in the Unity Editor

    EDIT:
    Figured it out was some weird behavior a script was causing not a HoTween bug
     
    Last edited: Dec 6, 2013
  35. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Whew great. I just saw the videos and was going to tell you something else must be happening, since I move like that most of my menus too. Glad you solved it :)
     
  36. Rateke

    Rateke

    Joined:
    Jul 19, 2012
    Posts:
    4
    I wonder if Hotween is capable of making an object with a texture make invisible to visible slowly.

    May you hep me?

    Regards.
     
  37. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi Rateke,

    as long as you have a numeric variable that you can change to make your material invisible, then you can. In your case, you could tween the color of a material to make it invisible. Just remember that when you change the properties of a material, unless you use the sharedMaterial property, you'll create a new instance of it, and thus you'll add an additional draw call to your rendering.
     
  38. hellobard

    hellobard

    Joined:
    Sep 26, 2012
    Posts:
    140
    hey Izitmee,

    I'm having some trouble with a HOTween sequence on multiple resolutions on iOS. My animation is a From animation using a new vector3 like in your examples. The animation is linked to an NGUI sprite that has an anchor on it. It acts correctly on iPhone 5, but on iPad, it doesn't take into account the different resolution and ends up in a completely different place than the position it should be going to. Is there a way to take the original position into account and position it say -300 pixels away like in iTween with NGUI?
     
    Last edited: Dec 12, 2013
  39. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi hellobard,

    I'm a little confused about what you're asking: you mean you'd want HOTween to convert a unit positioning into a pixel positioning automatically? If so, it could be implemented with an additional plugin, but I don't know how useful it might be (since I think it's more convenient if the coder makes the correct calculations himself and then tweens the corresponding values). If you want, the open-source code is all here, and if you make a PlugPixelTransform plugin or something like that, I will add it to the repository so it will come along with all HOTween updates.
     
  40. hellobard

    hellobard

    Joined:
    Sep 26, 2012
    Posts:
    140
    thanks for the quick response!

    yes, it seems HOTween works in unity units, while NGUI/iTween uses pixels to offset from animations. However this is not really my issue I think. I have some GUI elements, all attached to NGUI anchors. When using the HOTween From and with a prop position and "new Vector3(-2-2,0), they end up at the wrong position when running this tween. See this attached screenshot.

    $Screenshot 2013-12-12 20.35.25.png

    Oddly enough this is only happening to the GUI elements anchored to the bottom side of the screen.

    Edit: Changing the UIRoot manual height in NGUI will fix it per device, but only for one device. This is a very strange bug or a problem with the combination of NGUI + HOTween and the Retina Pro plugin...
     
    Last edited: Dec 12, 2013
  41. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    In reality, HOTween doesn't use neither units nor pixels. It just animates the numeric values of a property (number, Vector2/3/4, etc) from one starting point to an end point.

    I believe in your case there might be two reasons for what's happening:
    1) NGUI or some other script is also changing the position of the object you're tweening
    2) maybe you're tweening a localPosition, and NGUI is manipulating some other positioning value?
     
  42. hellobard

    hellobard

    Joined:
    Sep 26, 2012
    Posts:
    140
    Thanks izitmee, i'll have another look at it to see if I can get it working..
    NGUI doesn't have any tweens connected to one of the three misbehaving HOTweens, so I don't think that's the issue.
     
  43. gkara

    gkara

    Joined:
    Sep 7, 2013
    Posts:
    12
    Izitmee, thank you very much for HOTween.

    I started a small project where I have a few objects (at different starting positions) on a 3d path and I want to animate all of them for a small portion of the path when the user presses a key. So I use something like that for each object :

    Code (csharp):
    1. if (Input.GetKeyUp("right") )
    2. {
    3.     myTweener.UsePartialPath(stage1, stage1 + 2);
    4.     myTweener.PlayForward ();
    5.     stage1 = stage1 + 2;
    6.     if (stage1 >= 8)
    7.         stage1 = 0;
    8.  
    9.     // ... same for next objects (with different tweeners)
    10. }
    11.  
    12. if (Input.GetKeyUp("left") )
    13. {
    14.     if (stage1 <= 0)
    15.         stage1 = 8;
    16.     myTweener.UsePartialPath(stage1 - 2, stage1);
    17.     myTweener.GoTo(myTweener.duration);
    18.     myTweener.Reverse();
    19.     myTweener.Play();
    20.     stage1 = stage1 - 2;
    21.  
    22.     // ... same for next objects (with different tweeners)
    23. }
    1st question : Is there a better/more elegant way to do this (especially for the reverse direction) ?

    2nd question : myTweener.isComplete works only when the partial path goes in forward direction. When it's traversed at backward direction it always stays false. I would like to use something like :
    if (Input.GetKeyUp("right") (myTweener.isComplete)) { ... }
    so the user has to wait the partial path to be completed before giving a new order. So, is there a way to know when a backwards partial path is completed ?

    Thanks again
     
  44. Deleted User

    Deleted User

    Guest

    About your first question :

    Code (csharp):
    1. myTweener.UsePartialPath(stage1, stage1 + 2);
    2.  
    3.     myTweener.PlayForward ();
    4.  
    5.     stage1 = stage1 + 2;
    6.  
    7.     if (stage1 >= 8)
    8.  
    9.         stage1 = 0;
    10.  
    At first, you can rather do :
    Code (csharp):
    1.  
    2. myTweener.UsePartialPath(stage1, stage1 + 2);
    3. myTweener.PlayForward ();
    4. stage1 = (stage1 + 2) %8;
    For the rest, I'll let Izitmee answer ^^
     
  45. gkara

    gkara

    Joined:
    Sep 7, 2013
    Posts:
    12
    nice, thanks mton062 for this tip :)
     
    Last edited: Dec 17, 2013
  46. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Thanks mton062 for answering: I'm feverish today and probably would have blabbered some nonsense :D

    About knowing when a backwards path is completed, you could actually check for OnRewinded :)
     
  47. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    Hi Izitmee,

    I'm having an issue with a Sequence. Here's a simple repro case:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Holoville.HOTween;
    4.  
    5. public class TestSequence : MonoBehaviour {
    6.  
    7.     float currentValue = 0.0f;
    8.     public float CurrentValue {
    9.         get {
    10.             return currentValue;
    11.         }
    12.         set {
    13.             currentValue = value;
    14.             Debug.Log(currentValue);
    15.         }
    16.     }
    17.  
    18.     void Start () {
    19.         Sequence s = new Sequence();
    20.         s.Append(HOTween.To (this, 1.0f, "CurrentValue", 100.0f));
    21.  
    22.         s.Play();
    23.     }
    24. }
    When you run this and look at the console, you can see that the first output is 100 (the final value). This is causing an issue for me because I use the CurrentValue setter to perform some validation and set another variable depending on the value set by the tween.

    Here's the actual code to help you understand the issue:
    Code (csharp):
    1.     private int currentValue = 0;
    2.     public int CurrentValue {
    3.         get {
    4.             return currentValue;
    5.         }
    6.         set {
    7.             currentValue = value;
    8.             txtScore.text = currentValue.ToString();
    9.             txtScore.Commit();
    10.            
    11.             if (currentValue > bestScore) {
    12.                 txtBestScore.text = txtScore.text;
    13.                 txtBestScore.Commit();
    14.             }
    15.         }
    16.     }
    In this code, if the end value is greater than the bestScore, the bestScore text field is set to the currentValue. So you can see that having the end value set at the very beginning is an issue in this specific case.

    Thanks!
     
  48. gkara

    gkara

    Joined:
    Sep 7, 2013
    Posts:
    12
    It works fine now, thanks for your time.
     
  49. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @Dgizusse: saw your tweet, but didn't answer because I was travelling (and now I'm back and with a giant feverheadache, ach!). Sequences do that on startup, since they need to jump through the end-phases of all internal tweens in order to set the correct dependencies in case of connected sequenced tweens (like for example, when you animate the same property but in separate sequenced tweens). I see why it's an inconvenience in your case, but sadly it can't be changed (unless you can use a Tweener instead than a Sequence there, since regular Tweeners don't have this behaviour).
     
  50. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    Ok, thanks for the response!
    I'll propably use a callback to start a Tweener instead.

    Thanks and get better soon!