Search Unity

Prime31 GoKit Tween Library Live

Discussion in 'iOS and tvOS' started by prime31, Apr 26, 2012.

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jp, GoKit is a tween library. It makes no sense to use it for nothing more than a delayed method call.
     
  2. jptsetung

    jptsetung

    Joined:
    Jan 12, 2013
    Posts:
    51
    A tween that doesn't do anything makes sense to me, but maybe me I'm the only one. This should exist, for the same reason the "zero" exists.
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jpsetung, it isnt a tween if nothing is changing and it is a massive amount of overhead to use a tween lib to delay a function call.
     
  4. Ripline

    Ripline

    Joined:
    Jul 22, 2012
    Posts:
    3
    We're seeing variable behavior in our tween completions when they're in collections. Tracked it down to floating point error.

    In AbstractGoTween.cs, the update method has these lines...
    _totalElapsedTime = Mathf.Clamp( _totalElapsedTime, 0, totalDuration );

    // using our fresh totalElapsedTime, figure out what iteration we are on
    _completedIterations = (int)Mathf.Floor( _totalElapsedTime / duration );

    The duration in question is 0.2f. _completedIterations never gets set to 1. It's the last tween in a Flow, and the Flow is completing itself before the individual Tween can complete (due to the FPE). In this case, that means that tween's onComplete action never gets called.

    Suggestions on the fix? We could force the collection to manually walk the active tweens and pop the completions if they haven't. That'd fix this specific bug, though it seems like the general issue of the component tweens never finishing is a more general issue.

    dave
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ripline, feel free to send a pull request with the fix.
     
  6. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    GoKit is a lifesaver, thanks alot prime!
     
  7. jonbro5556

    jonbro5556

    Joined:
    Jan 1, 2013
    Posts:
    24
    Hey there! This lib is super cool! And now the question:

    Is there a way that I can have the tween start from whatever the existing state of the object is, rather than the state of the object when the tween was instanced?

    pseudo code
    Code (csharp):
    1.  
    2.  
    3. TweenFlow hover = new TweenFlow();
    4. TweenFlow active = new TweenFlow();
    5. // fill up both of these with the end states that I want them in
    6.  
    7. void onHover(){
    8.    hover.playForward();
    9. }
    10. void onActive(){
    11.    hover.pause();
    12.    active.playForward();
    13. }
    14.  
    When on active is triggered it starts from the initial state of the object, rather than the state of the object at the end (or the middle) of the hover tween. I would particularly like to be able to slide forward and backwards through these tweens as the objects change states. Is this possible? Do I just need to rebuild the tweens and then run them?
     
  8. jonbro5556

    jonbro5556

    Joined:
    Jan 1, 2013
    Posts:
    24
    Actually, on a closer look it seems like it is caching some variables, so it plays correctly just as long as every single time I play the tween it starts at the same time during the previously playing tween. Can't figure out how to override this caching though. If I can call a function to wipe the cache that would be perfect.

    == EDIT ==

    Got it working, you just need to pass your tween collection to a function that does this:

    Code (csharp):
    1.  
    2. void resetProps(AbstractGoTweenCollection tween){
    3.         foreach(AbstractTweenProperty prop in tween.allTweenProperties()){
    4.             prop.prepareForUse();
    5.         }
    6. }
    7.  
     
    Last edited: Mar 4, 2013
  9. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    What does the 2nd parameter in the GoSpline command do?
    Code (csharp):
    1. path = new GoSpline(points, false);
    Guessing, I would have thought that if 'true', the tweened value would snap to the points in the points list, and if 'false', the value would smoothly interpolate between the points.

    But when I specify 'false', the game object goes weird and heads in strange directions and doesn't even end up in the proper destination (but everything works fine if 'true').

    I'm not using a closed points loop, if that matters, and here's how I use the path:
    Code (csharp):
    1. Go.to(go.transform, speed, new GoTweenConfig().positionPath(path, false, GoLookAtType.NextPathNode).onComplete(TweenComplete));
     
    Last edited: Mar 4, 2013
  10. Imawizrd

    Imawizrd

    Joined:
    Jan 19, 2013
    Posts:
    20
    Is GoKit Flash compatible?
     
  11. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ed, I have no idea. Try to run the demo scene in Flash and you will find out.
     
  12. sergilazaro

    sergilazaro

    Joined:
    Mar 21, 2013
    Posts:
    3
    Apparently not, unfortunately: link.
     
  13. Trideka

    Trideka

    Joined:
    Mar 24, 2013
    Posts:
    16
    I'm having a small problem that I hope someone can help with?

    I have a rigidbody object. Parented to it is another object which is not a rigidbody.

    Tweening the position of the child object with a "Punch" easetype causes the child object to become permanently offset with succession per tween event.

    Any thoughts on how to keep the motion of the child object relative to the parent rigidbody and return to its original relative position to the parent?
     
  14. wisarut

    wisarut

    Joined:
    Mar 27, 2013
    Posts:
    3
    The version in asset store has bug with "UpdateType.TimeScaleIndependentUpdate"
    The version from github has bug with Go.from when set vector3(scale,position) to "relative = true" It's still not relative
     
  15. michael-bartnett

    michael-bartnett

    Joined:
    Jul 8, 2012
    Posts:
    8
    Is there a means currently within GoKit to specify your own setter/getter delegates for tweens? At the moment I need to make these awkward `_tween_myPropertyExposed` properties for stuff I'd normally want to keep hidden. I only have so much time to dig through the source, so figured I might as well ask before I resign to grin and bear it or otherwise start adding it on my own.
     
  16. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @michael, GoKit requires a standard .NET/Mono property in order to be able to animate it.
     
  17. michael-bartnett

    michael-bartnett

    Joined:
    Jul 8, 2012
    Posts:
    8
    @prime31 That makes sense, having looked at GoTweenUtils.

    However, if the TweenProperties all read and write via the delegates created from PropertyInfo.GetSetMethod/GetGetMethod, it stands to reason that if I provide a getter/setter delegates (each taking, I suppose, a targetObject so they could be used in TweenConfigs), a property name (doesn't even have to be a member of the target object, just a key/id), and the targetObject, that it feasibly work as a valid tween in the system, right?

    But all that aside, the real thing I'm regretting is that GoKit won't try to grab private getters or setters. What's the reasoning behind this?
     
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @michael, the reason is mainly encapsulation. If an outside system (GoKit in this case) needs to modify something (a property in this case) in order to keep things manageable it won't go looking for private properties. You can of course just change the property finder to allow private properties.
     
  19. michael-bartnett

    michael-bartnett

    Joined:
    Jul 8, 2012
    Posts:
    8
    @prime31 Alrighty, makes sense. I'll likely do the modification, but it's good to know that I won't be setting off any bombs other than those I plant myself. Thanks!
     
  20. sergilazaro

    sergilazaro

    Joined:
    Mar 21, 2013
    Posts:
    3
    I want to do an alpha crossfade using GoKit, between two 2D objects that are similar but have a few differences, and I have trouble using EaseTypes that have the desired result. This person tried the same thing (different frameworks, but still the same thing) and explains the problem clearly with a video.

    The main issue is that the curves needed for this aren't in the EaseTypes in GoKit. The curves shouldn't add to 1 except at the very beginning and ends, because of the way alpha compositing works.

    Is there any way at all to do this? Custom EaseType curves? Adding a new EaseType to my local GoKit code?
     
  21. yardlevy

    yardlevy

    Joined:
    Mar 28, 2013
    Posts:
    1
    I want to save the state of running GoTween at checkpoints or when my mobile app is pre-empted by a phone call our sent to background. I am using the UnitySerialiser package to save the rest of my game state, but I have not found an elegant way to save the state of running GoTweens primarily because the OnComplete() delegates cannot be serialised. The best solution I have come up with so far is to save the elapsed time of each tween, and then restore the tween state by recreating the tween and then calling goToAndPlay() to advance the newly created GoTween to the previously saved time. The problem with this is that it adds an awful lot of overhead in my code everywhere I create a GoTween to be able to save and restore it properly. Does anyone have better way to serialize GoTweens?

    Thanks,
    Derrick
     
  22. Nooch

    Nooch

    Joined:
    Dec 31, 2011
    Posts:
    18
    Is it possible to tween the alpha of a guitexture, using gokit?
    I can't seem to figure it out, but I'm sure it's doable.

    Thanks for any insight! :)
     
  23. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @nooch, I'm afraid I have no idea. I have never used a GUITexture before. Someone else who uses them may know.
     
  24. Nooch

    Nooch

    Joined:
    Dec 31, 2011
    Posts:
    18
    No probs, I just figured it out! :D

    Code (csharp):
    1.  
    2. var endColor : Color = Color(0.5,0.5,0.5,1);
    3. this.gameObject.guiTexture.color.a = 0;
    4. Go.to(this.gameObject.guiTexture, 1, new TweenConfig()
    5.      .colorProp("color", endColor, false)
    6.  
    The first 2 lines are just there so I can fade the texture in from 0 alpha.

    Anyways! This worked great, but opened up another question.
    In my example, I have a GUITexture, that has a GUIText as a child object (label on a button).

    Does anyone know how I would go about setting the alpha of both of them in one go?
    For example, in iTween I use the "FadeTo" or "FadeFrom" function, and it will fade all objects that are parented to the main GameObject.
     
  25. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    @Prime31 how come GoTweenChain does not have a setIterations() function? I am trying to make a tween that fades a color in and out repeatably (until I tell it to stop) and I thought that meant setting the iterations to -1. However there is no way to set that in the GoTweenChain (or Flow, etc) classes. Is there a reason that is missing from the "Go" classes?

    Thanks!
     
    Last edited: Jul 1, 2013
  26. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I can't seem to get "Force Straight Line Path" to work with the paths. No matter what, it treats the path as a curve at runtime. Any idea what's going on? Thanks.

    EDIT: Nevermind, didn't realize the asset you save out with the visual editor didn't store that flag for you. Had to set the bool manually when creating the GoSpline object.
     
    Last edited: Jul 6, 2013
  27. MartinW

    MartinW

    Joined:
    Feb 14, 2013
    Posts:
    14
    Should the timeScale value in GoTweenConfig be a float and not an int?

    AbstractGoTween
    public float timeScale

    GoTweenConfig
    public int timeScale
    GoTweenConfig setTimeScale( int timeScale )
     
  28. cesarpo

    cesarpo

    Joined:
    Jun 8, 2013
    Posts:
    97
    How does tween overrides work?

    Let's say I call one tween, and then before this one finishes, I call another one, that changes the same property on the same object, but to a different value. I want the last tween called on some object to be the only one active, right now seems that all the tweens run in parallel and the end result of calling multiple tweens on the same object with the same property is unpredictable. Is there some kind of override manager? Or some config? I'm thinking something along the lines of what TweenLite does, where you can specify the override behavior when two tweens "collide".

    edit:

    seems that GoDuplicatePropertyRuleType.RemoveRunningProperty does what I want :D
     
    Last edited: Jul 16, 2013
  29. Imawizrd

    Imawizrd

    Joined:
    Jan 19, 2013
    Posts:
    20

    Was DCalabrese's question ever answered/resolved? I'm encountering the exact problem at the moment. I have copied pasted my code into the demo scene (using the same path in both scenes) and it works but when I run it in my scene it doesn't work.

    Am i missing something?
     
  30. Imawizrd

    Imawizrd

    Joined:
    Jan 19, 2013
    Posts:
    20
    Never mind I worked it out.

    I had my cube as a GameObject not a transform. Would of been nice if the error said I needed a transform instead of throwing a null reference though.

    If anyone was wondering..

    what it was before:
    _tween = Go.to( Cube, speed, new TweenConfig()

    what i changed it to:
    _tween = Go.to( Cube.transform, speed, new TweenConfig()
     
  31. franktinsley

    franktinsley

    Joined:
    Jul 1, 2010
    Posts:
    130
  32. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    Guys I have a question the answer to which could sell me GoKit over iTween once and for all:
    Is there a function alternative to iTweens MoveUpdate and RotateUpdate and LookUpdate etc? and would you please give me a little example and how is the performance compared to iTween?
    txx
     
  33. Goldfinger

    Goldfinger

    Joined:
    Jun 28, 2012
    Posts:
    10
    Anyone got TweenChain to work from a Coroutine ?

    I have setup a chain that contains a series of TweenFlow's

    var chain = new GoTweenChain(new GoTweenCollectionConfig());

    var flow = new GoTweenFlow(new GoTweenCollectionConfig());

    // Fade in
    flow.insert(0.0f, Go.to(....));
    flow.insert(0.0f, Go.to(...));

    chain.append(flow);

    flow = new GoTweenFlow(new GoTweenCollectionConfig());

    // Fade out
    flow.insert(0.0f, Go.to(....));
    flow.insert(0.0f, Go.to(...));

    chain.appendDelay(1.0f);
    chain.append(flow);

    When I call restart on the chain from a Coroutine and yield on waitForCompletion() just returns soon as the chain starts but the completion handler seems to work and returns when the chain completes.

    chain.restart();
    chain.setOnCompleteHandler(c => Debug.Log("chain complete"));

    yield return chain.waitForCompletion();

    Debug.Log("Done");

    Is this a bug or am I missing something ?
     
    Last edited: Sep 20, 2013
  34. departement

    departement

    Joined:
    Jul 31, 2013
    Posts:
    11
    I'm having trouble animating a float inside a shader using GoKit. Here's what my code looks like:

    //--------------------------------------------------------------
    public override void Reset()
    {
    base.Reset();

    // Reset the animation.
    gameObject.renderer.material.SetFloat("_Blend", 0.5f);
    }

    //--------------------------------------------------------------
    public override void Animate(bool bLoop)
    {
    GoTweenConfig config = new GoTweenConfig();
    config.floatProp("_Blend", 1.0f, false);
    if (bLoop) {
    config.setIterations(-1);
    }
    Debug.Log("this.r.m = " + this.renderer.material.GetFloat("_Blend"));
    Debug.Log("this.t.r.m = " + this.transform.renderer.material.GetFloat("_Blend"));
    Debug.Log("go.r.m = " + gameObject.renderer.material.GetFloat("_Blend"));
    Debug.Log("go.t.r.m = " + gameObject.transform.renderer.material.GetFloat("_Blend"));
    Go.to(this.transform, 1.0f, config);
    }

    I'm still new to Unity, so I'm not sure what the correct way to access the attribute is. All four logs output the correct "0.5" value, but I think I've tried everything as the first param of the Go.to(...) method with no luck. I keep getting the following error:

    could not find property with name: _Blend
    tween failed to validate target: FloatTweenProperty

    Thanks for the help!
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @department, the property tweens will only work with .net/Mono class properties. Shader properties are a very different beast. You could certainly make your own tween to do this by subclassing AbstractTweenProperty. If you look at any of the current tweens you can see the pattern to make your own.
     
  36. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    I noticed from the shake demo that if you keep clicking very fast on any button the tween permanently changes the cube, i went to check the code and the buttons do complete the tween before starting a new one so i'm guessing there's a bug somewhere within gokit
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @kebrus, that is the expected behavior. If you want to run a bunch of shakes you should start the subsequent ones after the completion handler fires.
     
  38. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    ok, but then how do i really complete a tween? actually why does the demo even tries to complete the tween if that was the expected behavior?
     
  39. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    Any reason why the final frame of a tween wouldn't be called finish as part of a tween flow?

    I have a tween flow that tweens the alpha of several UIPanel objects (NGUI) from 0-1. Instead of finishing at 1, they finish at 0.9xxx or 0.8xxx

    For now I'm yielding the waitforcomplete routine and just forcing them to the proper values after the tweenflow becomes "complete" - but I'm sure there's something I'm doing incorrectly.

    Code (csharp):
    1.  
    2. // This is where I am setting up my tween flow
    3. _tween = new GoTweenFlow { autoRemoveOnComplete = false };
    4.         foreach (UIPanel panel in _panelsToToggle)
    5.         {
    6.             _tween.insert(0, panel.alphaTo(ToggleDuration, 1));
    7.         }
    8.  
    9. // This is my Panel.alphaTo extension method
    10. public static GoTween alphaTo( this UIPanel _panel, float duration, float endValue, float initValue = 0){
    11.         _panel.alpha = initValue;
    12.         return Go.to(_panel, duration, new GoTweenConfig().floatProp("alpha", endValue) );
    13.     }
    14.  
    15. // This is how I'm toggling the tween
    16. if (shouldEnable)
    17.             {
    18.                 _tween.playForward();
    19.             }
    20.             else
    21.             {
    22.                 _tween.playBackwards();
    23.             }
    24.  
     
  40. sparrow

    sparrow

    Joined:
    May 6, 2012
    Posts:
    17
    I had immense performance problems with my game and the cause were multiple iTween components running and causing garbage collection. Performance spikes were very frustrating and made game unplayable on older IOS devices like iPhone 4...

    After 3 days of rewriting all tweens to GoKit results are incredible and I could not be happier! Game runs smoothly, and I see no more spikes in performance.

    Big thanks to Prime31 and additionally hat goes off for making this plugin free. I have already bought one of your plugins and your coding style and quality are consistently top line. Keep up the good work!
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @sparrow, glad to hear you got a big performance bump!
     
  42. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    Is there a way to chain spline paths or am I doing it wrong?

    I get a "NullReferenceException: Object reference not set to an instance of an object" error. with the code below

    Code (csharp):
    1. spline = new GoSpline(cameraPath); //asset loaded from resources folder. Verified loaded.
    2.             config = new GoTweenConfig().positionPath(spline, true);
    3.             tween  = new GoTween(obj, 1.0f, config);
    4.             _cameraChain.append(tween);
    Interestingly enough, I do not get any error if instead of using positionPath I use something like scale.
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    That should work fine. Where exactly is the NRE happening? That should pinpoint the exact line that has a null object.
     
  44. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    Here is the complete error message:

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object PositionPathTweenProperty.prepareForUse ()
    2.  (at C:/Project/Assets/Plugins/GoKit/properties/specificTypes/PositionPathTweenProperty.cs:80)
    3. GoTween.onStart ()
    4. (at C:/Project/Assets/Plugins/GoKit/GoTween.cs:221)
    5. AbstractGoTween.update (Single deltaTime)
    6. (at C:/Project/Assets/Plugins/GoKit/base/AbstractGoTween.cs:89)
    7. GoTween.update (Single deltaTime)
    8.  (at C:/Project/Assets/Plugins/GoKit/GoTween.cs:129)
    9. AbstractGoTween.goTo (Single time)
    10.  (at C:/Project/Assets/Plugins/GoKit/base/AbstractGoTween.cs:307)
    11. GoTween.goTo (Single time)
    12.  (at C:/Project/Assets/Plugins/GoKit/GoTween.cs:249)
    13. AbstractGoTweenCollection.update (Single deltaTime)
    14. (at C:/Project/Assets/Plugins/GoKit/base/AbstractGoTweenCollection.cs:192)
    15. Go.handleUpdateOfType (GoUpdateType updateType, Single deltaTime)
    16.  (at C:/Project/Assets/Plugins/GoKit/Go.cs:77)
    17. Go.Update () (at C:/Project/Assets/Plugins/GoKit/Go.cs:98)
    Thanks again for your help!
     
  45. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jonathan, that is quite odd. It seems to be getting the NRE in the prepare phase. I'll see if I can repro and give this a closer look when time allows.
     
  46. jorjdboss

    jorjdboss

    Joined:
    Dec 25, 2011
    Posts:
    68
    @prime31:
    I'm using this for horizontal page scrolling. When I try to scroll again before the current tween has completed, the page skips to the new tween's target. Is there a way to pause/stop the currently running tween and make the object's current position, the start parameter for the overriding tween. Then you can safely replace the old tween with the new one and it'll be a smooth visual transition.
    iTween handles this well, but GoKit is faster on mobile.
     
  47. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jorjdboss, all tweens are fully controllable. See the included demo scene for how to pause, stop, rewind, restart etc. You have full control over the entire tween.
     
  48. jorjdboss

    jorjdboss

    Joined:
    Dec 25, 2011
    Posts:
    68
    Will look at the demos, thanks.
     
  49. db82

    db82

    Joined:
    Mar 14, 2012
    Posts:
    24
    Go.killAllTweensWithTarget(yourTarget);
     
  50. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    I'm facing a similar issue as well.

    The statement of "yield return chain.waitForCompletion();" doesn't make a coroutine to stop and it just kinda skips it.