A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Assets and Asset Store' started by Izitmee, Jan 7, 2012.
Very sorry if the question has it been asked, but is it possible to tween a public variable?. If yes, can you post an example?
Sorry if this question has been asked before, but google didn't help me
With the help of the example I found here :
I successfully used HOTween to make a character follow a path.
As I wrote code, I realized I needed a newer version of HOTween to take advantage of this function:
OrientToPath(0.02f, Axis.X | Axis.Z)
(the HOTWeen version available with the example seems older than the one you can find on the asset store)
Problem: With the newer version, I can't get my character to follow the path at constant speed
Here is a screenshot:
And here is the simplified code I'm using:
Vector3 playerPath = GetPathFromAnotherObject();
Prop("position", new PlugVector3Path(playerPath).
OrientToPath(0.02f, Axis.X | Axis.Z) ).
HOTween.showPathGizmos = true;
Can someone help me ?
Thanks in advance
I'm having an urgent issue. I released a game full of tweens for android and somehow Samsung phones are not running the tweens correctly, i can't really say if it affects all samsung phones, but the few we tested the behavior is as follows:
1. Any kind of hotween configuration and tween configuration runs without problems BUT update time scale is really really low, a tween of 1 second takes about 10 minutes to run to completion. Time.timeScale is okay. I've debugged it thoroughly and nothing seems wrong on my side, and in fact it runs well in all our other test devices including iOS, so basically this only happens on Samsung phones.
2. If i use indepent update timescale the tween doesn't even start
3. Updatetype.fixedupdate runs each update at aprox. 30 sec each
I tried running as a normal tween inside a function and even inside a coroutine. It doesn't matter. I have the latest version of hotween.
EDIT: i tried the demoscene and the bahavior is the same, everything is scaled down, meaning, the float tween increases rapidly but at very small numbers, the string tween types at a very slow pace (about a minute a letter), you can hardly notice any movement of the cubes.
Sorry for the late answers guys, but I'm still pretty sick
@ZJP: sure, that's what HOTween is all about For example, let's say you have a public float "someFloat", which is a member of a class instance you refer to as "someClass", you can do it in two ways...
Tween from inside the class itself:
HOTween.To(this, 1, "someFloat", 100);
Tween from a class which holds a reference to the someClass instance:
HOTween.To(someClass, 1, "someFloat", 100);
Obviously, you can use the TweenParms for more advanced usage.
@URZqqq: the examples have very outdated HOTween versions, and a newer one should always be replaced there. The fact that constant speed doesn't happen is very weird: I'll investigate :O
@kebrus: HOTween's update uses regular Unity Update and regular Unity Time.deltaTime to measure time, so the only possible reason is that on that Samsung Time.deltaTime returns wrong results. Can you test that?
EDIT: I'm publishing a game (Goscurry) on mobile right now, which has tons of tweens, but on all Samsung devices it was tested on I don't have this issue. What models did you use?
kebrus, that's quite scary! Have you hooked up the profiler? Also you don't happen to have vendor-specific logic elsewhere in your code, do you? Do you use while loops anywhere, like for downloading assets or something?
I just tried debuging delta time, on pc i get around 0.001 or 0.002 seconds, on my samsung test device i get 1E -05.
how could this be?
EDIT: @ God at play: I'm not using any specific code, but that doesn't even matter since i get the exact same result using hotween demoscene.
Izitmee, is there some way I can pause a tween, start another tween on that same property, and then resume the previous tween? Right now when I'm resuming the previous tween, it's not resuming, since I presume the newer tween has killed the previous one.
Hope you get well soon, too!
@kebrus: that's pretty crazy. It would mean that Unity's time.deltaTime is completely f****d up on those devices. You're absolutely sure that timeScale is ok, right? If so, the only solution is to open a support ticket with Unity, and while you wait for it to be fixed, you could investigate more and determine what is the timeScale variation, so you can increase it on those phones (like to 100) to simulate normal behaviours.
@God at play: as long as you pause the tween BEFORE applying the new one (no need to wait one frame, just one row of code under the other), and then resume the first one after the second one is complete, everything works (I just made a quick test to verify that). Maybe you're starting the other tween before pausing the first one?
EDIT: thanks for the get well wishes
That's good to know, I must have some detail wrong then. Here's my code:
public void ControlTweens (string id, TweenControlMethod method)
if (method == TweenControlMethod.PLAY)
if (method == TweenControlMethod.PAUSE || method == TweenControlMethod.RESUME)
List<IHOTweenComponent> tweens = HOTween.GetTweensById(id, false);
foreach (IHOTweenComponent t in tweens)
if (method == TweenControlMethod.PAUSE)
// get position to apply it back on resume (needed since resume isn't working on its own)
tweenPos = t.position;
else if (method == TweenControlMethod.RESUME)
// goto position saved during pause and play
Debug.Log(t.ToString() + " resumed at " + tweenPos);
if (method == TweenControlMethod.COMPLETE)
public void FlashLightning ()
TweenParms tweenParams = new TweenParms().
HOTween.To(sceneLightingStates[currentStateID], 0.2f, tweenParams);
tweenParams = new TweenParms().
HOTween.To(sceneLightingStates[currentStateID], 0.2f, tweenParams);
tweenParams = new TweenParms().
HOTween.To(sceneLightingStates[currentStateID], 0.2f, tweenParams);
public void ResumeLighting ()
I have 5 or 6 tweens and the other ones resume just fine, but these 3 here - the ones that have this new tween used on them - don't.
I found the culprit
After further testing we them found out the problem was only happening on some samsungs and with our player settings and eventually we found out the problem was the multithreaded rendering, for some reason it breaks Unity time on some devices, having it off solved the problem instantly.
I understand the concept of multi threads but i'm not really sure why was this problem happening, if anyone knows i would love to know. Still, thx Izitmee for the help, the unity time hint did help us find the problem.
@kebrus: glad you found the culprit. From what I know, the new mobile multithreading is sadly still rather buggy. But sooner or later it will hopefully work.
@God at play: one problem might be that you're using OnComplete on the first tween. So the two others will be completed in the same frame, but are not yet completed when the first one is. A Sequence would be better there, so you can call the Sequence OnComplete and make sure every tween has finished playing before restarting. Still, even if the previous tweens are not yet stopped, that shouldn't be an issue, so I'm thinking something else is at work there? Also, as a tip, instead of using a foreach each time you want to stop those tween, you could give them a specific id (or intId, which is even faster), and just call
which will pause all tweens with the given id (and you can do the same with Play/Complete/etc).
Thanks for the suggestion! I've tried something a little safer (see code) and have also implemented your suggestion - where possible at least. Still no resuming, and my output always shows the same position, confirming that the tween is indeed not resuming, although the 3 tweens are still accessed when I get them by id.
I've updated my code in the original post so as not to clog up the thread here.
Can you manage to reproduce the issue in a small project so you can send it to me? So I can check it out and see if something's wrong, or if there's indeed a bug somewhere.
By the way, I'm assuming you're using HOTween.Init to activate the OverwriteManager. Did you try to disable it and see what happens?
Thanks for being willing to take a look! I sent it your way. I did try to disable and that didn't make a difference.
EDIT: Arg, PM interface is annoying, resent to you!
I'm having some trouble with PlugVector3Path. It works with C# but not with Boo, and I can't figure out why.
The following simple test:
path as (Vector3) = array(Vector3, 1)
Gives the error: "'Holoville.HOTween.Plugins.PlugVector3Path' does not have a visible constructor that matches the argument list '((UnityEngine.Vector3))'"
It works however with the C#:
Vector3 path = new Vector3 ;
The C# and Boo snippets should be equivalent, both passing an array of Vector3, so I'm kind of stumped. Using C# is no big hurdle but since the rest of my stuff is written in Boo I would prefer to keep it uniform.
Thank you very much for writing this but I have an issue attempting to use it
sequence1 = new Sequence(new SequenceParms());
sequence1.Append(HOTween.To(gameObject.transform, 3, "position", Vector3(0,1,0)));
sequence1.Append(HOTween.To(gameObject.transform, 5, "position", transform.position));
sequence1.Append(HOTween.To(gameObject.transform, 3, "position", Vector3(0,0,0)));
I wanted a pause in between the tweens in the sequence but it seems to skip the second tween altogether.
@CrazyLikeAFox: ouch, the only possible reason for that is that Boo doesn't support optional parameters as C# does. Can you confirm that? In the meantime, fill that optional parameter by adding the pathtype (PathType.Linear or PathType.Curved) and it will work.
@NeophyteGamer: To add a pause to a Sequence, don't add a fake tween, but instead use AppendInterval:
Hi, thanks for HOTween. He's the best!
Please tell me how to do the following:
private IEnumerator Start()
var seq = new Sequence();
seq.AppendCallback(() => Debug.Log("Start"));
yield return StartCoroutine(seq.WaitForCompletion());
seq.AppendCallback(() => Debug.Log("After Wait")); //not play becouse isComplite == true
How to continue playing in this case?
Not sure what you want to do, since you're creating an empty sequence. If you want to use HOTween just as a timer, that's not its purpose, and since you're already inside a Couroutine you could directly use Unity's WaitForSeconds instead.
NEW HOTWEEN UPDATE V1.1.882
- Added PlugColor32 (automatically used in case of Color32 values)
- Added optional forcePlay parameter to all Reverse methods
- OverwriteManager now ignores paused tweens
- Fixed bug where GoToAndPlay didn't play if the tween was at the same position where it was sent via the goto
As usual, get it from the website, while I update the Asset Store package.
Hey Thanks for answering before but I have another question...
I can't seem to deploy on windows 8 phone, I installed the micro(?) version as according to your docs. I can deploy my other games normally so hotween is the only variable causing it... help? o.0
I know that people are using HOTween on Win 8 phone succesfully, so maybe there's other parts of your code causing the issue: I suppose HOTween is not the only thing that changes compared to your other games?
Alright you win, although it was a fresh project with only hotween in it, it seems the culprit comes from having too many developer apps on my phone. It can only handle two at a time.
Anyway great work on this thing, going to make my life easier.
No, I do not use sequence as timer, the above code only to simplify the example. I use HOTween.To within the sequence. In my case WaitForCompletion() waits executed HOTween.To
This is another example:
var target = PhotonView.Find(targetViewID).GetComponent<BaseCreature>();
var sequence = new Sequence();
sequence.AppendCallback(Owner.DoCast); //play cast animation
sequence.AppendInterval(Owner.CastDelay); //delay for Instatiate magicFX object
sequence.AppendCallback(() => magicFX = (GameObject) Instantiate(FX, Owner.MagicPoint.position, Quaternion.identity)); //Create magicFX object
yield return StartCoroutine(sequence.WaitForCompletion()); //wait until the object will be created
new TweenParms().Prop("position", target.MagicPoint.position) //move magicFX. If don't use WaitForCompletion in this line the object magicFX == null
magicFX object can not be created without sequence.
My question is how to continue to play the sequence again after WaitForCompletion()?
Wohooo!!! I win! I win! That said, it's crazy that you can't have more than two dev apps on your phone. Is it a limitation of Win8 phone, or of your specific type of phone?
@Artem86: Oh I see. In that case, the reason is that you can't create a sequence, play it, and then add more stuff to it. Once you play the Sequence, its contents are locked, and you have to create a new one (or a new Tweener) to move things more.
EDIT: in your case, you could create the first Sequence, wait for its completion as you're doing, and then just create a new tween for magicFX.
ok, thank you Izitmee
I dont understand the API very well. Can anyone tell me why sometimes this rotates clockwise, and sometimes counterclockwise? It seems pretty random which direction it chooses. I suspect it's tweening localRotation, and something in the parent hierarchy is rotated. Maybe.
HOTween.To(lastMoveMarker.transform, 5, new TweenParms().Prop("rotation", new Vector3(0, 45, 0)));
Already wrote about problem this problem.
I get this error on every frame and ALL TWEENS stop working. If I press "kill all tweens" in the inspector it's all fine again.
I finally get around to try and fix it. Added stored reference to tweeners and added Kill() to where enemy projectiles gets destroyed.
Not sure if it fixes it yet, as this bug is not easy to reproduce as it happens occasionally. Which is super weird most of the times it's fine if prefab with tween gets destroyed, but rarely it breaks everything! Or maybe it's because object I call HOTween.From gets destroyed could be the reason? Anyway it happens when enemy gets killed by explosion which destroys enemy projectiles as well, which have tween to scale them up when they shot by enemy.
Still, maybe you could add some sort of check for null reference, as it can be hard to clean tweens everywhere where object can be destroyed in some cases. Here is a error from latest version, v1.1.882, so line numbers should be ok, in case you will decide to do this:
NullReferenceException: Object reference not set to an instance of an object
Holoville.HOTween.Tweener.Startup (Boolean p_force) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:997)
Holoville.HOTween.Tweener.Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:986)
Holoville.HOTween.Tweener.Rewind (Boolean p_play, Boolean p_skipDelay) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:926)
Holoville.HOTween.Tweener.Rewind (Boolean p_skipDelay) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:278)
Holoville.HOTween.Tweener.Rewind () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:267)
Holoville.HOTween.Sequence.TweenStartupIteration () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:876)
Holoville.HOTween.Sequence.Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:903)
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:645)
Holoville.HOTween.Core.ABSTweenComponent.Update (Single p_elapsed) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Core/ABSTweenComponent.cs:954)
Holoville.HOTween.HOTween.DoUpdate (UpdateType p_updateType, Single p_elapsed) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/HOTween.cs:2073)
Holoville.HOTween.HOTween.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/HOTween.cs:666)
Optional parameters are indeed not implemented in Boo. Works perfect when supplying the PathType. Obvious error in retrospect, thanks!
@mindlube: the rotation will happen in the shortest "direction" needed to reach 0,45,0. If you want to rotate something BY 45, add a TRUE for the "relative" option, like this:
HOTween.To(lastMoveMarker.transform, 5, new TweenParms().Prop("rotation", new Vector3(0, 45, 0), true));
@tequibo: the reason is certainly because the target becomes null while still tweening. I recommend implementing some kind of destroy behaviour on each element, so you can clean event listeners, tweens, and other stuff. I implemented some checks to see if a target becomes null, but they don't always work because a) sometimes Unity is strange, and something might be null but not truly null, b) those checks are not called every frame, because otherwise they would slow the tween engine down.
Hi lzitmee, I want to make a persistent sequence in my scene, so I can append tweener and play them 1 by 1 anytime.
What I do is set sequence.autoKillOnComplete=false, and foreach tweener set tweenParms.AutoKill(true).
But it appearance that the tweener can't remove itself after complete, and new tweener can't be play if it was add after previous tweener finished.
What's the proper way to do this? Thank you
void Start ()
seq = new Sequence (new SequenceParms ());
seq.autoKillOnComplete = false;
StartCoroutine (Play ());
IEnumerator Play ()
yield return new WaitForSeconds (1f);
Rotate (2f); // this will run
yield return new WaitForSeconds (5f); // wait until the first one complete
Rotate (2f); // this will not
public void Rotate (float duration)
TweenParms _parm = new TweenParms ();
_parm.Prop ("rotation", new Vector3 (0f, -900f, 0f), true).Ease (EaseType.EaseOutSine).AutoKill (true);
seq.Append (HOTween.To (this.transform, duration, _parm));
Hi zhuchun. Sorry but that can't be done. Once you create a Sequence and start playing it, it becomes locked, and you have to create a new one (or a new Tweener) if you want to tween more.
Oh I see, thanks anyway
So, I've got my Vector3Path all working, however "OrientToPath" is giving me a headache. No matter what percentage I set it to at some point my transform it will suddenly flip and face backwards. My path is not that complex with mostly straight lines and some horizontal turns. I'm probably missing something obvious again.
Can you replicate it in a simple barebone project and send it to me? So I can check it out?
EDIT: even if you do it in Boo it's ok
OK. So it works perfectly when I do it in a clean project with basicaly the same kind of path, which means the problem is most probably with my code.
Uhhh that's a mystery then. Maybe you start another tween at some point which overwrites the previous one? Or you modify your transform manually for some reason?
Indeed. No nothing like that. My mostly straight path has not issues, but one which curves around (but does not close) has this wonky behaviour. As you can see from the screens, it starts out flipped, then corrects itself, (and afterwards flips back again).
Mhmm that seems one of the errors I had at the beginning of HOTween, and that caused me tons of headaches until I fixed it for good. I wouldn't know what to suggest unless you can replicate it though
I have this game:
And I want to be able to tap on any of the spawned shapes and use HOTween to change its position.
Does anyone know of a resource or tip to do this?
To change a position with HOTween, you can simply do like this:
HOTween.To(myTransform, myTime, "position", new Vector3(2,2,2));
To recognize a tap instead it depends on the way you scripted it all, but usually a simple raycast should be enough (I'm sure you can find tons of ready-made code here on the forums).
I get this error even though I have HOTween installed:
error CS0103: The name `HOTween' does not exist in the current context
The only call I have to HOTween is:
HOTween.To(pickedShape.transform.position, 1, "position", new Vector3(0,5,0));
If you want to use HOTween, you have to import the namespace in each class that uses it (see the "get ready to code" chapter in the intro).
Dude, you are super awesome!
As you can grasp, I am a beginner but I am super excited about HOTween and can't wait to learn more.
First of all I want to say thank you for your great job on developing HOTween.
And here is my question: I want to make some kind of static function, which will destroy object, which was tweened by HOTween.Tweener. It could be useful if you use alpha-off visual effect very often.
1) I have some toolkit 2d sprite and want to "alpha-off" it.
2) For that I will write next code:
TweenParms tweenParams = new TweenParms();
HOTween.To(view, 0.4f, tweenParams);
Where "TweenTools" is my custom created class and DestroyTargetOnTweenComplete is function about I have told. Here code of that function:
static public void DestroyTargetOnTweenComplete(TweenEvent tweenEvent)
Tweener tweener = (Tweener) tweenEvent.tween;
if(tweener == null)
Object targetObj = (tweener.target as Object);
if (targetObj == null)
// Here will be code of destruction tweener.target
3) The bad thing is tweener.target variabale is null. If I am understending source code correctly, it happens because variable target become null just after calling Complete function.
Am I right? And please, could you advice me some way to make independed static function for reason that I have wrote.
P.S.: sorry for my English.
I have just found that I can use OnStepComplete callback for my reasons (in that way variable target isn't null). But, anyway, I think that it will be useful if variable target aren't equal to null before OnComplete callback will be called.
@gegagome: thanks for your enthusiasm, and have fun with the beginning
@Flashist: you're totally right. I will check now and see how that can be changed.
Allright, after some fun with the Visual Editor I wanted to actually script some tweens, too and also combine my created Tweens in the Visual Editor with my scripts.
What I want to do:
- when my Character hits an enemy he looses health (duh!)
My code looks like this:
void OnTriggerEnter(Collider other)
if(other.tag == "EnemyTrigger")
if(playerHealth != 0)
playerHealth -= 1;
playerHealth = 0;
The string "HEART01_DOWN" is the ID of the Tween which is created at the HOTweenComponent of an UISprite-Object in my nGUI-UI.
When the game runs, the Tween is played. It's tweening/moving the localPosition of the Object. Everythings works fine.
But wait, there's more!
This tween only moves the heart down. I need not only the localPosition to change but also the Alpha-Value of the sprite, the localRotation and so on.
I looked up your Sequences and I think that is what I'm after, but I don't know how to create my special "tween-chain".
If the target is the same, you could use the same Tweener to tween multiple properties. That's not your case though, since you have different targets, so Sequences is the right way to go.
Here is how you would do it, where "myTween0/1/2" are regular tweens that you would create to animate those properties:
Sequence mySeq = new Sequence();
mySeq.Play(); // contrary to Tweeners, Sequences are created in a paused state
I'm using Insert to make all those tweens play together. If you wanted them to play in a row, you would use mySeq.Append instead.