Search Unity

HOTween: a fast and powerful Unity tween engine

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

  1. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Yes, the UILabel is available in Prefab-State.

    It's strange, but when I drag the Prefab in the scene, attach the Component to it IN the scene, THERE I get the UILabel as a target and can tween the properties. Hittin "Apply" and everything works fine. For now it works, but it would be nice if you could investigate. :)
     
  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Fixed! Here is a new Visual Editor version which works correctly with Components of prefabs too. Can you check it out and let me know if you have any issues with it?
     
  3. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Tried it out. Works just fine. Thank you very much! :D
     
  4. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Great! Gonna upload on the website and the Asset Store soon :)
     
  5. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    940
    Is it possible to create a tween to a target position, and then OnUpdate or something, change the target position?
     
  6. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    If with that you mean changing the final end value of a tween while it's running, then no, you can't do that :p
     
  7. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Hi, is that possible to change move speed percentage(duration) dynamically after sequence.Play()? Thank you!
     
  8. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi. You can't directly change the speed/duration, but you can change a Tweener/Sequence's specific timeScale at any time, thus achieving the same result.
     
  9. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    WOW! Changing seq.TimeScale is so easy and acts like a magic! Thank you:D
     
  10. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    You're welcome :D And just so you know, you can also animate said timeScale change, by creating a tween which has that Tweener as a target and timeScale as a property.
     
  11. gnp89

    gnp89

    Joined:
    Jun 25, 2012
    Posts:
    36
    Can you tell us something about how WaitForCompletion() : IEnumerable was implemented?
    I'm using HOTween for my game and found that very useful.
    Now I would like to implement my own yield instructions for my own objects. I appreciate any help!
     
  12. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hey gnp89, HOTween is a DLL but just because I greatly prefer working with assemblies: at its core it's fully open-source. You can check all the code you want here :)
     
  13. Ox_

    Ox_

    Joined:
    Jun 9, 2013
    Posts:
    93
    I'm trying to tween an object inside a moving container by using "localPosition", but it still uses global position in some way and moves to wrong coordinates.

    Is there a way to tween an object to coordinates relative to its parent?
     
  14. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hey Ox, if you tween localPosition, then I'm pretty sure that's what will be tweened (I use it all the time). Maybe you have something else moving your parent at the same time? Otherwise, post the code you're using so I can see if there's something wrong.
     
  15. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    hi there, is it possible to customize the bounce easetype? it feels like it's time and distance dependent but i would like to be able to control the animation a bit more, right now i have an object that tweens in a large distance at a small time so the bounce is really huge, should i use punch instead?
     
  16. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hey kebrus, to get the exact bounce you want, I'd suggest using an AnimationCurve as an ease.
     
  17. BTStone

    BTStone

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

    If I assign an ID to a Tween (with the Visual Editor), for example "Tween1" and use the same ID for another Tween. Will both Tweens be played if played by ID? If not: How can I manage this?
     
  18. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Yup, both will be played :)
     
  19. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    I'm trying to create a continuous random shaking effect but i can't seem to find out how, when using the shake function i can feed it a params object and tell it to loop indefinitely but that will make it loop with the exact same values, but i wanted that each loop had a random value. is it possible?

    thanks
     
  20. Demigiant

    Demigiant

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

    sorry but no. If you want random values you will have to create a tween which, using OnComplete, creates a new tween with random values each time it finishes.
     
  21. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    EDIT: Sent you a PM.
     
    Last edited: Oct 31, 2013
  22. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    981
    Hello,

    I want to cache a Tweener instance without starting it. It seems I can only get one through HOTween.To() or HOTween,From() and I hate doing this all the time:

    Code (csharp):
    1.  
    2. if(tweener == null) {
    3.     TweenParms parameters = new TweenParms();
    4.     parameters.Prop("someProperty", 0).Ease(EaseType.EaseInQuad).AutoKill(false);
    5.     tweener = HOTween.To(source, TWEEN_DURATION, parameters);
    6. } else {
    7.     tweener.Restart();
    8. }
    9.  
     
  23. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    981
    Got around it using Pause(). But it looks kinda silly (start something only to pause it). Is there a more elegant way?

    Code (csharp):
    1.  
    2. // in Awake()
    3. TweenParms parameters = new TweenParms();
    4. parameters.Prop("someProperty", 1).Ease(EaseType.EaseInQuad).AutoKill(false).Pause();
    5. tweener = HOTween.To(source, TWEEN_DURATION, parameters);
    6.  
    7. // then somewhere to play it
    8. tweener.Restart();
    9.  
     
  24. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi davenirline. That's the elegant way :) Tweeners are immediately started when created (contrary to Sequences), so the Pause method pararmeter is there exactly for those cases where you want to pause it and start it later.
     
  25. shaman_4d

    shaman_4d

    Joined:
    Nov 13, 2013
    Posts:
    2
    HI. I animate the box cap with tweener http://www.screencast.com/t/jlJizXb7ZgYt but as you can see box opened well. But when box closed there are some weird rotations. I use the next code for close:
    Code (csharp):
    1. TweenParms parms = new TweenParms().Prop("rotation", new Vector3(0f,0f,0f));
    2. HOTween.To(genBoxCap.transform,1f,parms);
    What is wrong?
     
  26. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    I suppose Unity changed the resulting Quaternion to something weird after the first tween is complete, so you should animate doing
    Code (csharp):
    1.  
    2. Vector3 currRotation = genBoxCap.transform.rotation.eulerAngles;
    3. new Vector3(currRotation.x - 90, currRotation.y, currRotation.z);
    4.  
    (if you're using the X axis)
     
  27. shaman_4d

    shaman_4d

    Joined:
    Nov 13, 2013
    Posts:
    2
    Izitmee, thanks a lot - It works now!
     
  28. mochatony

    mochatony

    Joined:
    Jul 24, 2012
    Posts:
    14
    Hello

    Would like to know is there a OnComplete function for Sequence class? I search the documentation but couldn't find it, or perhaps alternative way to know the sequence is complete?

    Thank you
     
  29. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi mochatony. Sure, here you can find all the SequenceParms, among which there are the same callbacks as with Tweeners.
     
  30. ketain

    ketain

    Joined:
    Aug 30, 2013
    Posts:
    2
    Hi Izitmee,

    I have not read all the 50 Posts so it can be that you already answered this.
    Since weeks I am trying to implement a decent spline based characterMovement with iTweens and it is kind of horrible.
    Until now it is ... acceptable but far away from what i really want.
    There is no possibility to have a constant speed when moving on a spline. This might be possible to achive within the next few days. What really causes me headaches is the Collision detection.
    I hacked something together that works somehow but it simply does not feel right and is somehow buggy. (And here i ignore the fact that it is a shame to not use the inbuilt collisionsystem of unity)

    But now i have found HOTween. But so far I have not found a way to directly manipulate the position of a character on a path.
    If you tell me this is possible and give me a hint how it works I will put my iTween stuff kindly in my lovely trashbin.
    Thanks in advance for your answer :)
    (I wont be able to read your (possible) answer until monday so do not wonder about my late reply then :))
     
  31. Demigiant

    Demigiant

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

    once your character is the target of a path, you can only move him faster/slower, or pause/play/rewind/etc it, and I'm not sure if this is what you mean with direct manipulation. Let me know something more about what you're trying to manipulate, and I'll tell you if it's doable.

    Also, for moving objects on a path with ease and additional controls, I definitely recommend Baroni's Simple Waypoint System. It implements HOTween and is very cool (and I say it because I made a small game with it, and it was very flexible).
     
  32. tequibo

    tequibo

    Joined:
    Jun 4, 2013
    Posts:
    19
    Hey, thanks for this great tween engine.
    I run into strange problem recently:
    Occasionaly it just stops working on some prefabs with this error message:
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. Holoville.HOTween.Tweener.Startup (Boolean p_force) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:968)
    4. Holoville.HOTween.Tweener.Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:957)
    5. Holoville.HOTween.Tweener.Rewind (Boolean p_play, Boolean p_skipDelay) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:897)
    6. Holoville.HOTween.Tweener.Rewind (Boolean p_skipDelay) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:278)
    7. Holoville.HOTween.Tweener.Rewind () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:267)
    8. Holoville.HOTween.Sequence.TweenStartupIteration () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:830)
    9. Holoville.HOTween.Sequence.Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:857)
    10. Holoville.HOTween.Sequence.Update (Single p_shortElapsed, Boolean p_forceUpdate, Boolean p_isStartupIteration, Boolean p_ignoreCallbacks) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:612)
    11. Holoville.HOTween.Core.ABSTweenComponent.Update (Single p_elapsed) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Core/ABSTweenComponent.cs:884)
    12. Holoville.HOTween.HOTween.DoUpdate (UpdateType p_updateType, Single p_elapsed) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/HOTween.cs:2016)
    13. Holoville.HOTween.HOTween.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/HOTween.cs:667)
    14.  
    It works great for the most part, but sometime on some prefabs it does not work. I'm not sure maybe it stops working altogether, only happened two times, I think, and I noticed it happen to two different instantiated prefabs. There were fine before and fine after, after running game again.
    Am I doing something wrong?
     
  33. ketain

    ketain

    Joined:
    Aug 30, 2013
    Posts:
    2
    With direct manipulation I mean that i can control the position of the attached GameObject with keys. The GameObject is not supposed to leave the path defined by HOTweens PlugVector3Path. My Camera is lookin in an 90° angle onto the character and is following him.
    If i press the right arrow key and hold it my character is supposed to move in the right direction following the set path and lookin onto the path. (if you imagine a camera in a 90° angle it will be right on the screen of the player but may be not in world space).
    if i release the key the character stops.

    If i press the left arrow the same will happen but i will turn around running to the opposite direction now.
    Might there be a possibility to achieve this with your scripts? Or if not, Might there be a possibility to achieve this with some tweeks within your code so you could point at the scripts i may need to change and i will do the stuff by myself?
     
  34. BTStone

    BTStone

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

    How do I check if a Tween is playing right now?

    I'm trying this, but that does not work:

    Code (csharp):
    1. public string ID;
    2. // Use this for initialization
    3. void Start () { }
    4. // Update is called once per frame
    5. void Update ()
    6. { Debug.Log(HOTween.IsTweening(ID));
    7. }
    Gives me always "False" in the Console, though the TweenID I set in the Script was played all the time.
     
  35. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @tequibo: I made changes to HOTween which I still didn't publish, so the error lines don't coincide. But that might happen if you're tweening something and it gets destroyed or becomes null?

    @ketain: you could always keep your character inside a container and tween the container along the path. Then when you want to move the character left/right, you can do that without issues, and since the container will still be moving along the path, it should give the result you're expecting. In practice, it would be a combination of tweens, while modifying HOTween code to achieve something like that differently would make no sense, since it's not in the scope of a tween engine :p

    @BTStone: IsTweening only works with a tween target, not with Ids :p
     
  36. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Ah alright!
    How are the chances it will work with IDs, too :D ?
     
  37. tequibo

    tequibo

    Joined:
    Jun 4, 2013
    Posts:
    19
    @Izitmee thanks for reply! yes, those prefabs gets destroyed, but component where HOTween is called attached to them. But maybe if prefab gets destroyed too early? I use it for effects on projectiles, like pulsing and scaling. So maybe if object is destroyed before some HOTween init this problem occurs?
     
  38. Starkadder

    Starkadder

    Joined:
    Oct 16, 2013
    Posts:
    3
    Hi Daniele!

    Sorry if this question has already been answered - I couldn't find it if it has!

    I'm creating a sequence that does not loop - let's call that mainSequence. However, I may wish to include a looping sequence within it - let's call that subSequence.

    I create mainSequence and set .loops to 0.

    I create subSequence and set .loops to 4, then append it to mainSequence.

    When I play mainSequence, subSequence only plays once - as though it has inherited mainSequence's .loops property.

    Is this expected behaviour? f this is expected behaviour, is there a way of achieving what I wish to achieve?

    Many thanks in advance!
     
    Last edited: Nov 19, 2013
  39. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @BTStone: that was easy to add. Get it here, and let me know if everything's ok :) With that, IsTweening works also with string and int ids.

    @tequibo: yup, that could definitely be the reason. When you (or Unity) destroys something, just to be on the safe side you should first kill all tweens.

    @Starkadder: hi! Yes, that's indented behavour, since when calculating a Sequence time, only the main Sequence loops are included. If you want to "trick" it, you could add an interval (with AppendInterval) after you add the subSequence with the loop, and make that interval long enough to accomodate all subsequence loops :)
     
  40. Starkadder

    Starkadder

    Joined:
    Oct 16, 2013
    Posts:
    3
    Thanks so much for the very quick reply!

    One further question - is it possible to include an infinitely looping subsequence within a sequence? Would I perhaps be better just using GoToAndPlay within mainSequence if I wished to achieve this?
     
  41. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    No way for nested infinite loops, but using GoToAndPlay would be a perfect way to achieve the same :)
     
  42. Starkadder

    Starkadder

    Joined:
    Oct 16, 2013
    Posts:
    3
    Great. Thanks again!
     
  43. tequibo

    tequibo

    Joined:
    Jun 4, 2013
    Posts:
    19
    @Izitmee I can call Kill() inside OnDestroy where possible, but is there a simple way to kill tween if I create it in another script, the same that instantiates object that is animated?
    I will probably try to implement some pooling solution anyway, so objects would not be destroyed but reused but still would be nice to know the right way of cleaning up tweens.
    Thanks!
     
  44. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    I personally use one of two ways to clean tweens, depending on how I create them:
    1) If I store the Tweeners in a GameObject, I make sure that when said GameObject gets destroyed I kill the tweens, like you do
    2) Same as above, but instead than storing Tweener/Sequence references I give them an IntId (which is faster than regular string Id), and use HOTween.Kill(id).
     
  45. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    That worked great! It recognizes the given string. Though there is one problem.

    So here is the same code again:

    Code (csharp):
    1.  
    2.  
    3. public string ID;
    4.  
    5. void Update ()      
    6. {        
    7.    Debug.Log(HOTween.IsTweening(ID));
    8. }
    9.  
    I set the ID in the Inspector. Till the very moment the Tween is played by ID it shows "False" in the Console, which is fine, but then when the Tween started it shows "True". And then it stays at "True", even when the Tween is finished.
    Possible reasons?
     
  46. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Uhm, I can't replicate this issue: on my side it reports everything correctly. Can you send me a small sample project which just has a cube or something replicating it, so I can look at it?
     
  47. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    I tried it now with one single Cube. Just FYI I'm using also the Visual Editor, there I set the initial IDs. I made some screens:

    Heres a simple Cube with the HOTweenComponent and an Tween-Setup:




    Here is an empty GameObject attached with the Debug-Method:




    So, when I start the game (the Tween was set to AUTO) it plays the Tween 5x as set up in the settings and the Debugger shows "TRUE". After the Tween reaches its fifth loop it stops after executing the fifth, which is correct, but the Debug.Log goes on stating TRUE:



    (Its set here at 1663, but when the tween stopped it was at 200.)
     
  48. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    I tried to replicate your setup with the Visual Editor, but again it's all working correctly here. It reports TRUE while playing, and then FALSE. Maybe you have other tweens with the same ID running?
    P.S. simple sample project still welcome if the above was not the reason ;)
     
  49. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    You'll receive soon a PM ;)
     
  50. Spikeh

    Spikeh

    Joined:
    Jun 7, 2013
    Posts:
    24
    Hey Izitmee,

    Just a quick one - is it possible to disable easing for a particular tween? I want a completely smooth tween with an abrupt start and end, but none of the easy types give me that. Closest I've got is EaseType.EaseInOutQuint...

    HOTween.To(_myobject,
    3,
    new TweenParms()
    .Prop("localPosition", new Vector3(x,y,z))
    .Ease(EaseType.EaseInOutQuint)
    );