Search Unity

HOTween: a fast and powerful Unity tween engine

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

  1. Matt1988

    Matt1988

    Joined:
    Sep 14, 2012
    Posts:
    23
    Hello Izitmee. I am enjoying HOTween immensely and I thank you for providing it to the community for free.
    I was wondering if there was a way to tween an objects position through rigidbody.MovePosition() with HOTween.
     
  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi Matt, glad you like it.

    There is no direct way to tween via rigidBody.MovePosition, but you can create a public Vector3 variable, animate that one, and use OnUpdate to set its value to the desired rigidBody.
     
  3. Matt1988

    Matt1988

    Joined:
    Sep 14, 2012
    Posts:
    23
    Oh! works perfectly, thanks.
     
  4. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    It would be awesome though to have a way to continuously change the end target value for a Tweener. I guess that would mean that every plugin should have a method to update it's cached internal calculations when it's called from the Tweener so the tween works correctly. What do you think?
     
    Last edited: Sep 13, 2013
  5. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Floky it's not only that... to update the end value in a smooth way, a new ease algorhythm should be created each time, otherwise it would be the same as killing a tween and creating a new one, and you would see unsmooth ease changes in-between. As such, it would require some rather complicated logic and a lot of time to do it all correctly, and I'm afraid I can't do it :p
     
  6. Lord Ned

    Lord Ned

    Joined:
    Dec 3, 2012
    Posts:
    11
    I'm trying to create an "intro" sequence that plays for my game's main menu. I've created a Sequence and set it to play when the GameObject is set to OnEnable, and then in the OnDisable I tell the sequence to Rewind/Restart.

    However, my issue is that it doesn't seem to be able to Rewind the sequence before it's disabled so when the OnEnable is played again everything is already in their final location so nothing appears to happen. Is there anyway to 'reset' the whole sequence instantaneously so that if I were to call OnDisable/OnEnable the sequence could start over?

    Code here: http://pastebin.com/uKCgFDMx
     
  7. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Sequences, like tweens, "kill" themselves after completion, to avoid staying in memory while they're useless. If you want to re-use a Sequence instead, you have to add the AutoKill(false) SequenceParm to it:
    Code (csharp):
    1.  
    2. _introSequence = new Sequence(new SequenceParms().AutoKill(false));
    3.  
     
  8. Lord Ned

    Lord Ned

    Joined:
    Dec 3, 2012
    Posts:
    11
    Your support has been nothing but amazing, thank you very much!
     
  9. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Well that was easy :D Thanks!
     
  10. Lord Ned

    Lord Ned

    Joined:
    Dec 3, 2012
    Posts:
    11
    Since you thought that last question was too easy, I got a harder one for ya!

    I have a 'curtain closing' sequence that is split into two sections: In one sequence the curtains close and then in the other sequence the curtains open up. These need to be able to be called in any order (ie: "open" them first), so I have a quick function that jumps everything their 'closed' position before calling the 'Open' position. This allows me to load a scene and have the curtains start closed (even though they're positioned in the editor in the 'open' position) and then have them open. This works fine.

    However, what doesn't work fine is doing this:
    CloseCurtains()
    OpenCurtains()
    CloseCurtains()

    The reason for this is that the end of the CloseCurtains sequence has a Callback appended to the the end of it and when I call _closeSequence.Rewind(); _closeSequence.Play() it immediately calls the Callback (which in this case actually triggers the curtains to open again) so I get this weird jumpy mess.

    Full code is here:
    http://pastebin.com/teVEHuTk

    Code Snippet is here:
    As you can see by the line before _openSequence.AppendCallback, I had to cheat with something else and use the OnComplete(..) of that because I was having similar issues with disabling the panels using an appended callback. It appears that when you rewind the sequence, either the callback is getting moved to time=0, or it's getting called immediately for some reason.

    Edit:
    Matter of fact, if I change line 53 (in the full-source I posted) to read this:
    _closeSequence.Append(HOTween.From(CenterSeal.transform, 0.1f, new TweenParms().Prop("localScale", new PlugVector3Y(0)).OnComplete(SequenceFinishedCallback)));

    And then comment out line 63, it works fine. I feel like I'm not using AppendCallback right, but I would assume this is how it's supposed to be used?
     
    Last edited: Sep 17, 2013
  11. ickydime

    ickydime

    Joined:
    Nov 20, 2012
    Posts:
    110
    Experiencing the exact same issue as seen by aquapete a couple months back (below). Unity can't decide which OnComplete function to call due to the params option.

    I'm trying to pass in (GameObject, string, object, SendMessageOptions) but its resorting to trying to call TweenCallbackWParams.

    I just grabbed HOTween from the AssetStore last week so I should be fully up to date. I'm not having trouble with any other tweens, even ones with OnComplete that do not take any params. Any thoughts? Thanks!


     
  12. ickydime

    ickydime

    Joined:
    Nov 20, 2012
    Posts:
    110
    Never mind.... false alarm!

    I was passing in a monoBehavior rather than a GameObject. I had assumed I needed to give the class in which the method was going to be called. But as I read up on SendMessageOptions it 'clicked'.

    Leaving my prior post to help anyone else that may make a similar mistake.

    Thanks!
     
  13. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @Lord Ned: damn you got me there :D That actually sounds like there might be a bug: I'll have to investigate. As a suggestion, in the meantime, if you need a final callback, you should add it to the SequenceParms instead than adding a callback at the end of the Sequence (or to the final tween). Like this:
    Code (csharp):
    1.  
    2. _closeSequence = new Sequence(new SequenceParms().AutoKill(false).OnComplete(SequenceFinishedCallback));
    3.  
    Also, just for shorter code, instead than calling _closeSequence.Rewind(); and _closeSequence.Play(); one after the other, you can simply call _closeSequence.Restart();

    @ickydime: thanks for posting and answering :)
     
  14. Lord Ned

    Lord Ned

    Joined:
    Dec 3, 2012
    Posts:
    11
    Thanks, that sounds like a cleaner solution for the mean time!
     
    Last edited: Sep 18, 2013
  15. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    HOTween Visual Editor update: v1.1.201

    - Fixed incompatibility issues with Windows 8

    As usual, I submitted it to the Asset Store, but while it's waiting to be approved, you can get it here
     
  16. ShoyukenX

    ShoyukenX

    Joined:
    May 11, 2013
    Posts:
    6
    I am having problems with speedbased tweens. I have two cubes moving at the same "Speed" but one of the cubes slows down. I am not sure if it may be a bug or I am using it wrong. Here is the example. I have uploaded the file to a free file host. Click on "Click here to start download from sendspace" http://www.sendspace.com/file/svxmrs
     
    Last edited: Sep 23, 2013
  17. Demigiant

    Demigiant

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

    sorry but for security reasons, I really don't want to download something from Sendspace. Instead, write here your tween code so I can check it out :)
     
  18. ShoyukenX

    ShoyukenX

    Joined:
    May 11, 2013
    Posts:
    6
    Got it.

    Ok. Here is the example. Let me know what is going on because I cannot figure out the reason why one of the cubes would slow down when both of them have the same "Speed"-based


    void Start () {

    /* Ignore this part. This is just to stage everything nice and neat */
    GameObject cube1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
    GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);

    cube1.transform.position = new Vector3(0,10,0);
    cube1.renderer.material.color = Color.red;
    cube2.transform.position = new Vector3(-4,10,0);
    cube2.renderer.material.color = Color.green;

    Camera.main.orthographic = true;
    Camera.main.orthographicSize = 10;
    Camera.main.transform.position = new Vector3(0,1,-10);
    /* END */



    // ***** START HERE *****

    // Cube 1 (RED)
    Sequence mySequence = new Sequence();

    mySequence.Append( HOTween.To(cube1.transform, 2f, new TweenParms().Prop("position", new Vector3(0,-6,0), true).SpeedBased() ) );
    mySequence.Append( HOTween.To(cube1.transform, 2f, new TweenParms().Prop("position", new Vector3(0,-6,0)).SpeedBased() ) );
    mySequence.Play();


    // Cube 2 (Green)
    HOTween.To(cube2.transform, 2f, new TweenParms().Prop("position", new Vector3(-4,-6,0)).SpeedBased() );

    }
     
  19. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Issue found! SpeedBased tweens don't work inside Sequences. You'll have to make two separate Tweeners without placing them inside any Sequence.
     
  20. Deleted User

    Deleted User

    Guest

    Or you can also keep your sequence, without using the SpeedBased thing, but calculating the time in function of your wanted speed. That's what I used for my project.
    So that's an alternative way to do a speed-based tweener, 'cause then you just have to set your wanted speed.
    => HOTween.To(mythingtomove.transform,(1.0f/vitesse)*(mymove.distance), ... );

    You just need to know/calculate the distance of the move, before :)
     
  21. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    mton062's workaround is actually my favorite and I recommend it, if Sequences are needed (though to be honest, I still never used speed based tweens in my games) :) Highfive!
     
  22. dmutt

    dmutt

    Joined:
    Jun 3, 2013
    Posts:
    17
    Could you elaborate more. I am having the line 117 error warning also. Thanks.
     
  23. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hey there!

    Is there a way to tween a prefab with the Visual Editor?
     
  24. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @BTStone: hey there! For prefabs, you have to use the HOTweenComponent and attach it directly to a prefab

    @dmutt: I hope ickydime will elaborate more. But if not, you can send me a link to a basic Unity project that reproduces this issue, and I'll look into it (though not before next week, because tomorrow I'm leaving and will be busy until the end of the weekend).
     
  25. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    This is awesome. Thank you! :D
     
  26. dmutt

    dmutt

    Joined:
    Jun 3, 2013
    Posts:
    17
    I am at work now, away from the project. I will try to get you a sample scene file with the line 117 issue this weekend sometime. Thanks.
     
  27. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Critical BUG, In Tween or Sequence, OnComplete where throw an exception will run into infinite loop.

    Code (csharp):
    1.  
    2.     HOTween.To(cube.transform, 0.2f, new TweenParms().Prop("localPosition", Vector3.zero)
    3.                 .OnComplete( () => { throw new Exception(); } )
    4.       );
    5.  
    Code (csharp):
    1.  
    2.  
    3.     Sequence tweenSequence = new Sequence(new SequenceParms().OnComplete(() =>
    4.         {
    5.         throw new Exception();
    6.         }));
    7.  
    8.  
    9.         tweenSequence.Append(HOTween.To(cube.transform, 0.2f, new TweenParms().Prop("localPosition", Vector3.zero)));
    10.         tweenSequence.Play();
    11.  
    12.  
     
  28. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Hi - hoping someone can help me out with a problem I'm having. I've just converted my game over from iTween to HOTween in order to build a Windows Store version.

    The game is turn based and the tweening stuff is only done when either the player or enemy is taking a turn. That all works fine. What I'm finding though is that if I just leave the game sitting for a moment (maybe 20-30 seconds) waiting for the player to take their turn (i.e. nothing is moving around), I'll suddenly see "Hotween : 1" appear in the Hierarchy and the errors below will start generating in the Console. At that point, Unity hangs and I have to force quit.

    At the time when this happens, there are no HOTweens being called by my code - nothing is moving around at all, everything is just idle. Does HOTween itself run any sort of GC or something that might be causing this to happen?

     
  29. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Okay - apologies if I'm a dumbass :) I'm totally new to HOTween. I just discovered[FONT=Lucida Sans Unicode, Lucida Grande, sans-serif] HOTweenMicro and imported that instead. I can still see the "Hotween : 1" appearing when nothing is happening, but I'm not getting the errors anymore and the Editor isn't crashing. Me happy.[/FONT]
     
  30. ShoyukenX

    ShoyukenX

    Joined:
    May 11, 2013
    Posts:
    6
    Thanks for the help Daniele and mton062. Now back to the drawing board.
     
  31. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Having further issues with the rotation of a light source in my day/night cycle.

    Here's the old iTween code. Essentially each time this is called, the light source rotates on its x axis by 15 degrees.

    Code (csharp):
    1.  
    2. iTween.RotateAdd(gameObject, iTween.Hash("x", 15.0f, "time", 5.0f, "easetype", iTween.EaseType.easeInOutSine));
    3.  
    Have tried a bunch of options in HOTween and can't get anything to work.

    For example, I'm doing this right now:

    Code (csharp):
    1.  
    2. HOTween.To(MyTransform, 5.0f, new TweenParms().Prop("rotation", new Vector3(15.0f, 0.0f, 0.0f), true));
    3.  
    The light starts at rotation (90,0,0). On the first run of the above code it ends up (75,180,180). Then next run it's (90,0,0), and back and forth.

    Also tried non-relative and feeding it the actual rotation each time (e.g. 105, 120, 135, etc). This also runs backwards giving me 75, 60, 45, etc. And the Y and Z axis are constantly jumping around.

    Can anyone tell me the correct way to do this?
     
  32. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Does HOTween work with Physics.

    Thanks.
     
  33. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @yuewahchan: why throwing an exception there? If you just want to be warned about something with a red label, you can Debug.LogError

    @SteveJ: glad you solved the first issue. About your second one, you have to take into account that Unity rotation system works with Quaternions, not Vector3. So you can feed a Vector3 to a tween animation, which will be automatically converted to Quaternions, but the Unity editor rotation inspector will show the equivalent of that same rotation converted to and then from Quaternion (where 75,0,0 is equal to 75,180,180). In short words, you can never rely on the fact that your Vector3 rotation will have the same values once converted to/from Quaternions, but you can rely that it will have the equivalent rotation value.

    @rocki: you can animate any physics property, but there are no special methods for physics tweens.
     
  34. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    How would you go about doing something like this:

    Use Case: A Rolling ball game that switches between physics and tweening on a path.

    1. Ball is on a spline path, user flicks the ball and it starts rolling on the path.
    2. then at a certain speed, the tweening takes over and keep the ball rolling on the path at a constant speed.
    3. After the ball rolls for some time via the tweening sytem, the user flicks the ball again to give it more speed, the physics system takes over and increases the speed. Then step 2 begins again after the ball slows down to a certain speed.

    Thanks.
     
  35. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Okay, but how do you solve the problem? :) The iTween code provided above works, so I was trying to find the equivalent HOTween code. I've ended up just doing things manually (with transform.Rotate) for that portion of the code. Everything else that I'm doing is a position tween, which works fine with HOTween.
     
  36. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @rocki: if you have a physics system setup so that it can run on a spline, I would honestly see no reason to change to a tween and then back to physics. Just use physics to keep the ball at constant speed while not being flicked again :) Jumping into tween mode in the middle of a spline can be done, but it would be rather complicated to setup, and since you need keypoints for a spline, it wouldn't be exactly as expected unless the tween jumped in at an exact keypoint.

    @SteveJ: using a relative rotation of 15,0,0 should return the exact same result as that iTween code (even if I don't have a good knowledge of iTween, but that seems what that code should do), meaning your target should rotate only 15° on the X axis. I thought the only problem was that the Inspector was returning different Vector3 values, while still being the same Quaternion result. Could you tell me more if there are other issues with that particular tween?
     
  37. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Yep - the problem is that it rotates forwards, then backwards, then forwards, then backwards, etc when called repeatedly. It should always rotate in the same direction.

    I'll see if I can get demonstrate it in a little sample project and send you a link to the ZIP.
     
  38. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Here's a project demonstrating the issue.

    http://www.stevejarman.com/temp/TweenTest.zip

    You can jump back and forth between iTween and HOTween in the Start function.

    Code (csharp):
    1.  
    2. private void DoRotate()
    3. {
    4.     iTween.RotateAdd(gameObject, iTween.Hash("x", 15.0f, "time", 1.0f));
    5.     //HOTween.To(transform, 1.0f, new TweenParms().Prop("rotation", new Vector3(15.0f, 0.0f, 0.0f), true));
    6. }
    7.  
    8.  
     
  39. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    It is for demo only, so in any case that it has exception inside the OnComplete. e.g. if there is a null pointer exception.
     
  40. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @SteveJ: Thanks for the example, gonna check it tomorrow.

    @yuewahchan: exceptions usually break stuff, I don't consider that a bug. I prefer not to check if there are null pointers or stuff like that, otherwise HOTween would become full of additional checks (or even worse try/catches), and those would make it slower. I usually assume it's up to the users to write code that doesn't throw exceptions :p
     
  41. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @SteveJ: I ended up testing your project today, and now I see what you're talking about. Gonna investigate it more tomorrow.
     
  42. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    First of all, link on your site in Support section that is supposed to link to this thread, links to main Unity forums page instead.

    Secondly, in visual editor, I'd like to be able to make animation sequences kinda like I can do that in Source Film Maker. Would make creating in-engine cutscenes much easier.

    Of course I realize that this is big feature I'm asking for, so no sweat if you can't do that.

    //edit: Does it work with Unity Free?
     
  43. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Oops, thanks for warning me about the link darkhog, just fixed it.

    About animation sequences, once I was thinking about it, but then Animator came out and I let it be. Animator is now open-source, and I already made some changes in HOTween which would've allowed it to work with it, so if anyone wants to expand on that, HOTween is ready. As of me, I am way too busy to tackle something like that at the moment :p

    P.S. yup, works with Unity free :)
     
  44. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Hi - did you ever get a chance to look into this further?
     
  45. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hey Steve, I apologize but I was greatly derailed by other jobs. I worked on it a little, and I think I found the right solution, but I'm still not certain and will need more tests. Today or tomorrow I'll post a test build so you might help me on that :p
     
  46. Spikeh

    Spikeh

    Joined:
    Jun 7, 2013
    Posts:
    24
    Hi Daniele,

    Been using Hotween quite a lot - it's given me some great results, but I'm currently banging my head against a wall here - trying to get the PlugSetColor plugin to affect a custom shader property, but keep getting errors like this:

    I've tried all sorts of different combinations for the "property" value, but I can't get it to work. It doesn't really make sense for it to require the property parameter, as the PlugSetColor() class takes the shader property name.

    Am I trying to do something it's not built to do? The here, here, and here doesn't really help - I can't find any examples of how to use PlugSetColor in there, just the parameters it takes etc (which I'm already setting correctly I believe).

    Here's my code:

    Tweener _glowTween = HOTween.To(glowRenderer.material, 2f, new TweenParms()
    .Prop("SetColor", new PlugSetColor(new Color(0, 0, 0, 1)).Property("_OutlineColor"))
    .Loops(-1, LoopType.Yoyo));

    "SetColor" is a method on the material, so I don't imagine that would work, but that's the last thing I tried before I gave up (I also tried "color" and a few other things)! _OutlineColor is the actual shader property name I want to tween. I would like to make the shader property tween back and forth between two colours.

    Can anyone give me a hand? It seems almost impossible to search through threads on the Unity forums... and a search on Google keeps plonking me on page 12 of this thread, with no sign of the content I've searched for!
     
  47. Spikeh

    Spikeh

    Joined:
    Jun 7, 2013
    Posts:
    24
    Well, just look at that. The very next thing I tried worked fine! "shader" seems to do the trick:

    Tweener _glowTween = HOTween.To(glowRenderer.material, 2f, new TweenParms()
    .Prop("shader", new PlugSetColor(new Color(0, 0, 0, 1)).Property("_OutlineColor"))
    .Loops(-1, LoopType.Yoyo));

    After 17 years of doing this, I should really learn to take a break if I'm struggling with something :p
     
  48. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @SteveJ: ok, this rotation thing drove me crazy. I found a solution, but then I started making more advanced tests than the one you sent me (like with objects already rotated 45° on two axis) and started having more issues. While solving those, I realized an important thing. The real solution is no solution - and possibly a limitation of HOTween's non-gameobject-oriented philosophy. Let me explain better.
    For example, to solve the fact that a Transform's Quaternions can sometimes have inverted coordinates, I could simply check if there's an inversion, and revert it. That way, your test project would work perfectly. But the problem is, what if the user knew the Quaternion coordinates were inverted and wanted to tween upon that base? I have no way to know that, and in that case the tween would be wrong.
    So, the solution, which is a pain in the ass, would be to check by yourself if the coordinates are inverted, and tween by -90 instead than 90.
    If you or someone else thinks my logic is faulty, please let me know so we can discuss it :p

    @Spikeh: sorry for the confusione there. The PlugSetColor doesn't really use the property you pass, but it still wants it to exist, otherwise it will throw an error.
     
  49. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hey there.

    I want to tween the UILabel-Property of a NGUI-Label. When the label is in the scene I can tween the Label and it's properties (it shows me the inner elements "transform" and "UILabel" and there I can tween the other properties). That's fine.

    But I have some Prefab-Labels and when I attach the Hotween-Component I can't select the UILabel as inner-element-target :(

    Edit:

    Same goes for every other prefab with NGUI-Components on it (UISprites etc.)
     
  50. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hey BTStone,

    I don't use NGUI so I can't test this directly, but does NGUI has the UILabel component available also when in prefab state? Or maybe it just creates and attaches it when placed into a scene? I'm asking because, if it's the second case, then there's nothing I can do. Otherwise I will check it out hoping to recreate a similar setting without NGUI.