Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

DOTween (HOTween v2), a Unity tween engine

Discussion in 'Assets and Asset Store' started by Demigiant, Aug 5, 2014.

  1. kurasu1415

    kurasu1415

    Joined:
    Jan 27, 2015
    Posts:
    6
    Is it possible to get the length of a path? HOTween seems to have this feature, but it doesn't look like DOTween does. I need this to ensure that tweens along paths of different lengths are all the same speed.

    If that isn't available, is there any way to make an object move along a path a set distance? Like, be able to say move x units along path y?

    Thanks in advance.
     
  2. waspswarm

    waspswarm

    Joined:
    Oct 2, 2013
    Posts:
    7
    Thanks again for the reply.

    I actually did a check earlier to see if I was ever passing over a NULL to the DOTween.Kill call and even with that check things don't work (i.e. only passing over non NULL components). Also as an additional test if I comment the DOTween.Kill() call out most of the tweens seem to look fine like they did in 0.9.310 but I will need to take a closer look. We use this KillTweens extension when we need to potentially interrupt/stop a tween that might be playing or when we don't want multiple tweens running on some of these objects. Let me know what you find.
     
  3. chetanisinanand

    chetanisinanand

    Joined:
    Oct 22, 2012
    Posts:
    22
    Hi,

    I'm trying to fadeOut a gameobject along with its children, I tried :
    DOTween.ToAlpha (( ) => this.renderer.material.color,x => this.renderer.material.color = x,1f, 0.5f );

    however, its not working as the main gameobject don't have renderer attached to it . Its children have renderer or some of them are Sprite.


    Earlier i used iTween and it worked fine and was able to fade gameobject along with its childrens,
    iTween.FadeTo (gameObject, iTween.Hash("alpha",0,"time" , 0.5f ));

    I believe this can be done using DoTween, please help me with code or suggestion,
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Hello, I've just downloaded HOTween for the very first time and after running the init have v1.0.050.

    For whatever reason I cannot tween a transform at all. I've tried various DO* calls on various transforms but the OnKill handler just gets called immediately, and the OnStart handler never gets called. I have Verbose logging but nothing prints out to indicate a problem.

    I can tween a camera colour with no problems, and the handlers get called fine.

    EDIT:

    I've discovered something. It wasn't working when the transform to be tweened was being passed through in the parameter to an OnClick handler for a Button. I tried using a normal public reference to the same transform in my script and it did work. Any clue why this would be?
     
    Last edited: Jan 28, 2015
  5. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @kurasu1415 Finished adding it. I'm fixing another issue and then I'll send it to you via mail.

    @waspswarm I found the issue. What causes it is the new "complete" parameter added to DOTween.Kill in v0.9.430. The problem is that Unity breaks C# rules with UnityEngine.Object types, allowing them to be converted to booleans implicitly. So when you call DOTween.Kill(myTarget) it is actually interpreted as DOTween.Kill(true). It's a terrible choice on their part (implemented to make things work more Flash-like with UnityScript I suppose) and I'm trying to find the best solution to fix this (other than making all bool parameters non-optional anymore, which I would like to avoid).

    @chetanisinanand Hi! Are your objects inside a Unity UI CanvasGroup? Because in that case you can use CanvasGroup.DOFade and it will fade all its contents. Otherwise, if you want to fade all sprites inside a Transform container, you can do this:
    Code (csharp):
    1. SpriteRenderer[] renderers = myContainer.GetComponentsInChildren<SpriteRenderer>();
    2. foreach (SpriteRenderer r in renderers) r.DOFade(0, 0.5f);
    @andymads Hello! And... weird! Gonna check it out as soon as I finish solving @waspswarm's issue
     
  6. chetanisinanand

    chetanisinanand

    Joined:
    Oct 22, 2012
    Posts:
    22
    @Izitmee post#803

    I'm not using UI CanvasGroup at this point,
    Rather, I've GUITexture and GUIText as child of given gameobject
     
  7. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    UPDATE 1.0.080
    • CHANGE: All static DOTween methods that affected all tweens (like the parameter-less version of DOTween.Kill()) have been renamed to DOTween.KillAll/RewindAll/EtcAll, in order to fix a bug when calling some of them. You will be warned (with an error log) inside Unity editor if you have to change your code accordingly
    • NEW: Added myTween.ForceInit()
    • NEW: Added myTween.PathLength()
    • BUGFIX: Fixed DOTween.Kill(myTarget) and other similar static methods being interpreted as DOTween.Kill(true) because of Unity's implicit conversion of UnityEngine.Object types to boolean
    BEWARE THE API CHANGE! It was the only way to fix a bug (due to Unity breaking C# rules, shame on me for not realizing that sooner).


    @waspswarm This fixes your issue.
    @kurasu1415 PathLength added :) Just note that if you want to use it before the tween starts you'll have to use ForceInit to finalize the path.
     
  8. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @andymads Tried to replicate your isse but everything works correctly here even if using an OnClick handler. Can you paste the full OnKill debug log, so I can see who's truly killing the tween?

    @chetanisinanand You will have to get all the GUITexts/Textures then and tween them separately. Sorry but DOTween has no "fade all in container" shortcuts for old UI elements.
     
  9. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Will we always have the do the "Setup" process? When I switch from using a PC to a Mac my project seems to lose all its DOtween references and I have to reimport a new version of the library and run the SetUp again. I'm not sure if this is a Dotween thing or perhaps a git control thing but its very annoying.
     
  10. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Code (CSharp):
    1. OnKill
    2. UnityEngine.MonoBehaviour:print(Object)
    3. TestDOTween:OnTweenKill() (at Assets/!My Stuff/TestDOTween.cs:29)
    4. DG.Tweening.Core.TweenManager:Despawn(Tween, Boolean) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween.Assembly/DOTween/Core/TweenManager.cs:185)
    5. DG.Tweening.Core.TweenManager:DespawnTweens(List`1, Boolean) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween.Assembly/DOTween/Core/TweenManager.cs:704)
    6. DG.Tweening.Core.TweenManager:Update(UpdateType, Single, Single) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween.Assembly/DOTween/Core/TweenManager.cs:384)
    7. DG.Tweening.Core.DOTweenComponent:Update() (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:49)
    8.  
     
  11. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @aholla It's a GIT thing. Check that it didn't set DOTween stuff to read-only and that its folder is versioned correctly.

    @andymads Mhmm everything seems alright and the tween is simply killed after completion. Can you paste me the OnClick method you're using?
     
  12. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Ok, that'll be tomorrow morning now.
     
  13. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @andymads The OnClick method might suffice, but if you want to make things quicker tomorrow morning it would be great if you could also replicate the issue in a barebone project and send it to me, so I can check everything out.
     
  14. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Was thinking about this on my way home. I was confused because when I investigated it looked like the transform parameter being passed in to my OnClick handler was null but how could it be if I was calling the DOTween method on it. Then I realised that it's probably an extension method that I'm calling so that would be ok?

    So I think that even though I've plugged in a standard cube object into the Transform parameter of the OnClick it's coming through as null for some reason, so the DOTween extension method is getting the null transform, and I suppose it just drops out?

    So it's most likely not a problem with DOTween, but something odd about how Unity passes through parameters in OnClick. Will investigate more tomorrow.

     
  15. waspswarm

    waspswarm

    Joined:
    Oct 2, 2013
    Posts:
    7
    Thanks again! You are right, that is a terrible implicit conversion! Changing those API to the *All() versions did in fact do it! We are good again!
     
  16. chetanisinanand

    chetanisinanand

    Joined:
    Oct 22, 2012
    Posts:
    22
    Hi,
    Is there a way to pass "from" and "to" value to a DOFade so that CanvasGroup always fades from given "from" value to "to" value,
    for example : CanvasGroup.DOFade(float from,float to, float duration);
    or let me know if this can be achieved somehow ?

    Anyway..Thanks for your great help !
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Code (csharp):
    1. CanvasGroup.alpha = from;
    2. CanvasGroup.DOFade(float to, float duration);
    ?
     
  18. kurasu1415

    kurasu1415

    Joined:
    Jan 27, 2015
    Posts:
    6
    @Izitmee Thanks for such a quick addition to the API.

    Is there a way to stop a Path tween from slowing down as it gets close to the end of the tween? My object moves at a constant speed along the path until the very last node where it slowly decreases speed as it gets closer to the end. I am essentially doing this :

    Code (CSharp):
    1. transform.DOPath(waypoints.ToArray(), 5, PathType.CatmullRom)
    2. .SetLookAt(0)
    3. .SetOptions(true)
    4. .SetSpeedBased(true);
     
  19. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @andymads Maybe you're assigning a different transform than the one that contains the OnClick parameter?

    @waspswarm Glad it works now. And yup, terrible way to break C# rules with those implicit conversions Unity implements.

    @chetanisinanand As the masterful @Baroni says :) Or if the "to" to reach equals the current target's value, you can also use From:
    Code (csharp):
    1. CanvasGroup.DOFade(fromValue, duration).From();
    @kurasu1415 DOTween uses an OutQuad ease by default. If you want constant non-eased movement for all the path you need to change it to Linear. You can do that either on the tween itself, or globally for all tweens.
     
  20. kurasu1415

    kurasu1415

    Joined:
    Jan 27, 2015
    Posts:
    6
    @Izitmee Perfect! Thanks again. I can't wait for the editor!

     
    gjf and OnePxl like this.
  21. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Looks like there's a bug in Unity. There's something similar in the Issue Tracker that's marked as fixed in 4.6.2.

    This is my OnClick handler that takes a transform and does a tween on it.

    Code (CSharp):
    1.     public void TweenTransform(Transform transform)
    2.     {
    3.         if(null==transform) print("transform is null");
    4.  
    5.         _tween = transform.DOScale(new Vector3(2,2,2),1f);
    6.  
    7.         _tween.OnStart(OnTweenStart).OnKill(OnTweenKill);
    8.  
    9.         print(_tween.ToString());
    10.     }
    11.  
    Here's my button OnClick setup. Cube has just been dragged from the Hierarchy window into the slot, just like you would do for a Serialised Transform field on a script.

    Screen Shot 2015-01-29 at 08.00.24.png

    The problem is that the object actually passed through to the handler parameter is a GameObject even though it's typed as a Transform. This means that in this case the parameter is actually null. This is causing DOScale to do nothing but trigger the OnKill handler immediately.

    This is the log.

    Screen Shot 2015-01-29 at 08.11.20.png

    Can you put some extra checking into the DO* methods to perhaps log a warning about calling with null?

    EDIT:

    Turns out this is indeed a Unity bug. I reported it and they said that it's an existing known bug.

    http://issuetracker.unity3d.com/issues/onclick-ui-button-onclick-with-transform-passes-null
     
    Last edited: Jan 30, 2015
  22. bojlahg

    bojlahg

    Joined:
    Dec 29, 2011
    Posts:
    13
    Why not to add Wait(float duration) to DOTween.
    To allow for example run callbacks after timeout.

    DOTween.Sequence().Append(DOTween.Wait(2.0f)).OnComplete(TimeoutCallback);

    This for example does not work right now:
    DOTween.Sequence().AppendInterval(2).OnComplete(TimeoutCallback);
     
    Last edited: Jan 30, 2015
  23. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @andymads That is a weird bug that I never noticed (must've been introduced by Unity 4.6.2, because I'm using 4.6.1 and the transform is passed correctly). Thanks for the explanation. About log warning in case of NULL target, I put it in my todo list and will do it soon.

    @bojlahg Now your example works (see v1.0.120 attached) :)

    @gregduret @tjjoss This attached update also implements a tweenable Tween.fullPosition property (which represents the time position loops included, delays excluded).
     

    Attached Files:

  24. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    654
    TL;DR
    DOTween 1.0.080 shows no tweening when I explicitly call DOTween.Init() (with any combo or args or none) but works fine if I do not.

    Hi
    I'm gradually phasing over from iTween. Am using DOTween for camera shaking. I'd originally wanted to increase logging to check an odd hitch. I'm using camera.DOShakePosition(float, Vector3, ...). It's the only use of DOTween so far.
    I added the OnKill() logging you suggested above and it shows normal cleanup after expected time.
    Will continue fiddling with this but am starting to get rather frustrated. Any thoughts most welcome!
    Thanks!
     
  25. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hi @Arkade,

    I just double checked DOTween.Init, and everything works perfectly here and all the tweens run correctly even after calling it. Can you create a barebone example and attach it so I can see what's wrong? Or paste the code here directly if it's not too long?
     
  26. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    654
    Thanks for reply and check. Yup, minimal reproduction here works fine too. That's what's confusing me so. :-(

    AHHA! I think I have something. If I disable my other camera affector (main camera controller), the shake works regardless of init. That one affects transform.position and I knew I needed to separate. Always wondered why they both worked. Perhaps it's something timing related (such that the extra Init() being called during play allows the shake to work?). Anyway, think this will fix. Thanks.
     
  27. chetanisinanand

    chetanisinanand

    Joined:
    Oct 22, 2012
    Posts:
    22
    Hi,

    I've a gameobject "A" as a parent and gameobjects "B" and "C" as its children. A Script is attached to Gameobject "A" , and I'm tweening Gameobjects "B" and "C" from there.
    For best performance ,
    1. Do I need to initialize DoTween in the script attached to A ?
    2. or do i need to attach saperate scripts on B and C for Initialization?
    3. DO I need to initialize it for every child(i.e B and C) separately ?
    4. What would be best SetCapacity arguments? DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10);
     
  28. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    I wanted to say Thanks for this great tween engine. Been using HOTween and now switched to DOTween and I really like where it is going!
    I have two questions and thought that maybe you could answer them:
    1. I can't find the link to the API reference on your site. There was a new easing added, Unset. I wanted to check out what it means, but couldn't find the API reference.
    2. I'll explain the structure of my game, so you could better understand my issue. My game has a MainMenu scene and many levels as separate scenes. Each level has various moving mechanism that create DOTween sequences in their Awake methods. By default DOTween autoPlays both tweens and sequences. I need sequences to start only when I trigger them, so in my MainMenu scene I set autoPlay to TweensOnly and when I launch a level from the MainMenu, it all works as expected. However when I'm just creating and testing the levels, I don't launch them from the MainMenu, but rather load the level scene and press Play. This skips the custom DOTween init from the MainMenu and autostarts all the sequences in that level. As the sequences are created in various Awake methods, I don't see a way to properly Init DOTween and set defaultAutoPlay before the sequences are created.

    Seeing how you already have a DOTween Utility Panel, I thought maybe you could expose there some of the default values used to auto-initialize DOTween? This way you don't have to explicitly initialize DOTween with custom values, you could just set those values in the Utility Panel. (You could use a ScriptableObject or something similar to store these values per project)

    Thanks!
     
  29. adeloid

    adeloid

    Joined:
    Feb 1, 2015
    Posts:
    1
    first thanks for your precious tool,

    and second i think i find the reloading freeze bug,
    it happen when making pause script for your project by setting unity timeScale=0
    then DOTWEEN timeScale will automatically change to zero and by pressing our restart level button the unity timeScale will change to 1 after reloading but DOTWEEN timeScale still remain on zero so the animations will freeze.
    it will be solve if you change unity timeScale to one before reloading scene(or your level) so DOTWEEN timeScale will change to one automatically.
     
  30. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Arkade glad you fixed that.

    @chetanisinanand Hi. DOTween.Init needs to be called only once in your project, before any other tween is created. So you can initialize it in A. For SetCapacity, it depends on the max tweens you think you might have active at one time. When I want to be safe, I usually set them to 500/500 (but I use tons of tweens and sequences), though I have a game where I have more than 1000 tweens running together, and just few sequences, so I go with 1500/200.

    @Devil_Inside Hiya! Glad you're liking the new version! I chose to make the docs but not to show the API because, to make DOTween lighter, I use many extension methods, which would make a generated API document pretty confusing. Unset is used internally by TweenParams, so they know that the ease has not been set.
    About your second point, I totally understand. I recommend setting your project up so that you always have a "CoreBrain" (or something) MonoBehaviour present in all your scenes. That way you can setup everything you need (not only DOTween but also audio etc) independently from the scene you play first. That said, I'm actually implementing the setup system you mentioned from the Utility Panel :)

    @adeloid Glad you like it! I will check out what you said in the next couple days, to see if I can fix it.
     
    Devil_Inside likes this.
  31. chetanisinanand

    chetanisinanand

    Joined:
    Oct 22, 2012
    Posts:
    22
    @Izitmee : Thanks a lot for your excellent support and awesome product , I'll always recommend this product to others :)
     
  32. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    Ah, that totally makes sense! Thanks for the quick reply!
    It's really awesome that you're already working on that Utility Panel.
    Thanks again!
     
  33. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @adeloid I made some tests and everything works perfectly here when setting timeScale to 0 and reloading. I think you might actually not be setting Unity's Time.timeScale to 1 again after you reload.

    @Devil_Inside @Little Big Monkey I was implementing the Utilty Panel DOTween setup and I decided I don't like it. Let me explain. The only way to implement that is:
    • allow the Utility Panel to create a ScriptableObject in DOTween/Resources, which will contain all the chosen settings
    • when DOTween is initialized, load this object from the resources and apply the settings
    Now the problem is that, unless you call DOTween.Init yourself (and calling DOTween.Init yourself is what you want to avoid, so it's a nono), the very first tween you run will be slower than the rest. Because it won't only have to initialize DOTween, but also to load the Resources asset.

    Sooooo... Thinking more about it, I have another solution. What if I create a GameObject that you can quickly add to a scene via a command, and whose Inspector allows to setup all DOTween's default values etc? Not only it would be more efficient, but the added advantage is that it will call DOTween.Init immediately instead than when the first tween starts.

    Let me know your opinions, or if you have other ideas.
     
    hopeful likes this.
  34. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    I don't know how much time it takes to deserialize a scriptable object, but I agree that it might be a problem.
    That said, I'm not sure I like the idea of a special GameObject per scene. I'll explain why. Let's call this GameOobject "CoreBrain" as you suggested earlier. I see 2 issues with creating additional CoreBrains per scene:
    1. The CoreBrain script on that CoreBrain gameojbect will need to be added to the project's "Script Execution Order" list and moved above the default time, to make sure it executes before any other awake method, where a tween can be created.
    2. The CoreBrain object will be added to every scene, and will need to be a "Singleton". Seeing how Singletons in unity are not real Singletons, that leads to situation, where on every scene load a new CoreBrain object will be instantiated and instantly destroyed.

    Edit: I've tested how long it takes for unity to load and read some values from a scriptable object. On iPhone 5c it took on average 1.5ms, on PC it was on average 0.6ms.
    I think this is an acceptable overhead not only for a corner case, but for general use as well (considering it only happens once per session). What do you think?
     
    Last edited: Feb 3, 2015
  35. exitsimulation

    exitsimulation

    Joined:
    Feb 10, 2014
    Posts:
    82
    Hey Izitmee,

    thanks for this cool update to HOTween - will definitely donate if this package suits my project.

    Can you tell me if this is possible:
    I want to animate Blend Shapes programmatically with DOTween.
    BlendShapes are set with SkinnedMeshRenderer.SetBlendShapeWeight(int index, float value).
    Is it possible to animate this parameter with DOTween? If yes, how? :)

    I'm not sure if it's even possible to animate function calls like this... Please tell me.

    Thanks!
     
  36. PhilllChabbb

    PhilllChabbb

    Joined:
    Sep 16, 2013
    Posts:
    8
    Hello Izitmee,

    I am a big fan of HOTween and decided to switch to DOTween. Would like to say a huge thanks and congrats on the release! :D

    I am curious if there will be examples put up soon on the website? I'm more of an artist, and having a little bit of trouble doing simple things like changing the speed of a tween. Right now here is what I'm doing to update the speed :

    //update speed
    transform.DOKill();
    transform.DOMoveY(transform.position.y + bobbleAmount, speed).SetAs(tParms);

    Sorry if my code looks really inefficient. Haha! I know this library is really powerful and beautiful, just need to learn it more. (Wanted to share the perspective from someone leaning more on the artistic side) Thanks again for all your hard work! Looking forward for the updates. :p
     
  37. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Devil_Inside I wanted to say that I pondered about it and actually liked your prefab idea very much (I read it yesterday but from the phone so I couldn't answer—I can't write from the phone, I really can't :B), but your EDIT made me realize I'm just exaggerating and yes, let's go with ScriptableObject :) Coming very very soon!

    @monogon Hiya! Here you go, for example :)
    Code (csharp):
    1. DOTween.To(()=> mySkinnedMeshRenderer.GetBlendShapeWeight(0), x=> mySkinnedMeshRenderer.SetBlendShapeWeight(0, x), 1, 2);
    @PhilllChabbb Hi! You're totally right, I really should add more examples (though you get some if you get the Asset Store version), shame on me! Will try to do that as soon as possible.
    As a hint about changing the speed of a tween, consider that you can change a tween's timeScale even while running:
    Code (csharp):
    1. Tween myTween = transform.DOMoveY(transform.position.y + bobbleAmount, speed).SetAs(tParms);
    2. // later....
    3. // Make it double fast
    4. myTween.timeScale = 2;
     
  38. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    Yeah, that prefab thing seemed like a great idea, until I realized that you still need to somehow reference the prefab :D, as otherwise it won't be included in the build and would need to be loaded from the resource folder... Which brings us back to ScriptableObject :)
    I'm glad you decided to go with ScriptableObject and I hope there are no other pitfall that we haven't though about.
     
  39. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Devil_Inside Voilà :) The attached 1.0.150 has an additional tab inside the Utility Panel, called Preferences, from which you can set all defaults etc. It will create (or modify if already created) a "Resources/DOTweenSettings.asset" file inside the DOTween folder, which will contain all the settings and which will be loaded at runtime when calling Init or auto-initializing.

    dotween_preferences.png

    Let me know how it works for you.
     

    Attached Files:

    Devil_Inside, Baroni and PhilllChabbb like this.
  40. PhilllChabbb

    PhilllChabbb

    Joined:
    Sep 16, 2013
    Posts:
    8
    Hello Izitmee! Thanks alot for the speedy reply. (really helped a lot) :D I didn't know you could the Asset Store version... will check it out now! Excited to dwell deeper in this awesome engine. ;D ♥<('_'<)
     
  41. Trevise

    Trevise

    Joined:
    Mar 31, 2014
    Posts:
    13
    Hello! This is my first taste of tweening and I love it! Your system is so easy to use! So first, THANK YOU!

    The issue I'm having is a strange one. I've got a prefab with this code:
    Code (csharp):
    1. gameObject.transform.DOShakePosition(0.5f,6,80,140,false);
    And it will shake the correct prefab, but it will also shake the prefab that had shaken previously. So the first time I click on it works perfectly. The second time both instances shake, and so on from there. Is there a fix for that?
     
  42. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @PhilllChabbb Ahaha I bow to your emoticon expertise :D

    @Trevise DOShakePosition can't shake more than one transform, since it allows only for a single target. Maybe you're calling that method on more than one MonoBehaviour or something like that?
     
  43. Mr_Cad

    Mr_Cad

    Joined:
    Dec 7, 2013
    Posts:
    27
    I'm trying to FadeIn FadeOut in 2d Toolkit

    But it doesn't work
    Code (CSharp):
    1.  
    2. tk2dBaseSprite[] sprites = popup.GetComponentsInChildren<tk2dBaseSprite>();
    3. for (int i = 0; i < max; ++i)
    4. {
    5.             if (i < sprites.Length)
    6.             {
    7.                 Color color = sprites[i].color;
    8.                 color.a = 0.0f;
    9.                 sprites[i].color = color;
    10.  
    11.                 // fade in
    12.                 color.a = 1.0f;
    13.                 DOTween.To(()=> sprites[i].color, x=> sprites[i].color = x, color, TRANSITION_DURATION).SetEase(Ease.OutQuad);
    14.             }
    15. }
    Somehow I noticed part of it works. As in if I don't call it in a loop, and maybe I only apply this method on a single sprite, the fadeIn/Out effect is working.

    Previously it works on HOTween
    Code (CSharp):
    1. TweenParms param = new TweenParms().Prop("color", color);
    2. HOTween.To(sprites[i], TRANSITION_DURATION, param);
     
    Last edited: Feb 6, 2015
  44. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    Thank you so much! That worked perfectly!
    The only thing I noticed is that the Reset button after a few test launches won't reset to the initial settings, but rather to the settings that I once set. Though that happened only in one project, and in all the other projects I tested, the Reset button worked fine. Anyway, that's a non-issue for me.
    Thank you!!!
     
  45. Trevise

    Trevise

    Joined:
    Mar 31, 2014
    Posts:
    13
    I'm betting you are right, thanks!
     
  46. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Mr_Cad That can happen when using the generic way in for loops without declaring the target. It's actually a bug of NET (fixed since a very long time, but Unity still uses the old version). You should declare sprites as a variable inside your for loop, and then everything will work:
    Code (csharp):
    1. if (i < sprites.Length)
    2. {
    3.    tk2dSprite sprite = sprites[i];
    4.    Color color = sprite.color;
    5.    color.a = 0.0f;
    6.    sprite.color = color;
    7.  
    8.    // fade in
    9.    color.a = 1.0f;
    10.    DOTween.To(()=> sprite.color, x=> sprite.color = x, color, TRANSITION_DURATION).SetEase(Ease.OutQuad);
    11. }
    @Devil_Inside When doing RESET I take the default settings from the DOTween class itself, which shouldn't change until runtime. Maybe you pressed it while the project was playing? Anyway, I'll hard-code them so it will be better after all. Also, I'm gonna add a way to also set the Tweener/Sequence startup capacity :)
     
  47. ilovemypixels

    ilovemypixels

    Joined:
    Oct 16, 2012
    Posts:
    6
    Hi there.

    I have a simple question but i'm not finding it that simple at all. I have a ton of Tweens, love them, I created some text with GameObject > UI > Text now I just want to fade these in and out, I can't figure it out at all.

    myTitle.DOFade is not enough info for it. I have a canvas object that my titles are the children of but I want to fade them individually.

    thanks for any help you can give

    Will
     
  48. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hiya @ilovemypixels

    To fade out an UI Text (called "myTitle" as in your case) you just do this:
    Code (csharp):
    1. myTitle.DOFade(0, 1); // Fade out in 1 second
    and to fade it in this:
    Code (csharp):
    1. myTitle.DOFade(1, 1); // Fade in in 1 second
    In short, the first parameter is the alpha value to tween to (0 to 1), while the second is the duration.

    P.S. "myTitle" must be a reference to the Text component, not the GameObject to which it's attached
     
  49. fermmmm

    fermmmm

    Joined:
    Oct 18, 2013
    Posts:
    129
    I've found a bug where OnComplete is not olways being called but happens in a slow computer I have and not in a faster one in where my game has a better framerate. The tween is the following:

    WalkTweenY = DOTween.To(()=>Character.WordPos.y, (p)=>
    {
    Character.WordPos = new Vector3(Character.WordPos.x, p);
    }, targetPos.y, Character.WalkSpeed).
    SetSpeedBased().
    SetEase(Ease.Linear).
    OnComplete(OnTweenYCompleted);

    I've checked it a lot of times and I'm 100% sure this is a problem with DoTween. I'm using the last version.
    I think this is going to be a very hard to catch bug but I can help you. Maybe we should make a teamviewer session or something like that. What do you recommend?.
     
  50. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    Yeah, it's entirely possible that I accidentally clicked the reset button while in PlayMode. That must be it. Thanks!
    Today I ran into another issue. I'm running a generic tween for a float with an OnComplete callback on an object that can be destroyed mid-tween. The problem is that after the object is destroyed, the tween is still running and the callback is being called on an object that doesn't exist (safemode is on)
    I've made a few tests that left me confused. Maybe you could clarify in more detail why things work the way they work.
    1. Safemode Off
    a. Start a generic tween on myTransform with an OnComplete callback. Deleting the object mid-tween results in console being spammed with hundreds of "MissingReferenceException" errors until the tween ends. The OnComplete callback is never called.
    b. Start a generic tween on a private Vector3 (or float) with an OnComplete callback. Deleting the object mid-tween doesn't generate any errors while the tween is running. When the tween completes, it generates an error in the OnComplete callback, because I reference the deleted object in that callback.​
    2. Safemode On
    a. Start a generic tween on myTransform with an OnComplete callback. Deleting the object mid-tween results in no errors, the tween seems to be killed properly and OnComplete is never called.
    b. Start a generic tween on a private Vector3 (or float) with an OnComplete callback. Deleting the object mid-tween doesn't generate any errors while the tween is running. When the tween completes, it generates an error in the OnComplete callback, because I reference the deleted object in that callback.​

    Both cases 1b and 2b have exactly the same behaviour and both are a bit confusing. Why in 1b there are no spamming errors and why OnComplete is called on an object that shouldn't exist? Why in 2b the tween is not killed and OnComplete is called when the tween completes?
    If that's expected behavior, can you please explain why that happens? Is it because Transform is passed by reference and Vector3 by value, and you have separate ways to deal with different types? What, in your opinion, would be the best way to avoid errors when running a tween on a primitive type or struct with OnComplete callback?
    Thanks!