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
    @bitever, you LookAtType.None to not affect the rotation or you can use LookAtType.TargetTransform to have it oriented towards another Transform.
     
  2. db82

    db82

    Joined:
    Mar 14, 2012
    Posts:
    24
    How can I reference the tween target through the onStart, onComplete handlers? I'm guessing there is a reference to it in the AbastractTween parameter but can't see where.

    Thanks for any help!

    Code (csharp):
    1.  
    2.  
    3. Go.to(child, 3f, new TweenConfig()
    4. .localPosition(new Vector3(0,200f, 0))
    5. .setEaseType(EaseType.Linear)
    6. .onComplete(BubbleAnimFinsihed)
    7. );
    8.  
    9.  
    10. protected void BubbleAnimFinsihed(AbstractTween tween)
    11. {
    12. Object tweenTargetObject = tween.target; ???
    13. }
    14.  
     
  3. Rafael-Costa

    Rafael-Costa

    Joined:
    Jul 7, 2012
    Posts:
    14
  4. geniuscd

    geniuscd

    Joined:
    Aug 10, 2012
    Posts:
    23
    hello @prime31,

    im using this code to rotate some GameObejcts, but its not looping infinitely , although I set the iterations to -1 ..... it only loop once.
    appreciate your reply

    Code (csharp):
    1. public Transform CircleOne,CircleTwo;
    2.     public float circleOneSpeed =18f,circleTwoSpeed=25f;
    3.    
    4.     private Tween tweenCircleOne, tweenCircleTwo;
    5.     private TweenFlow timeline;
    6.    
    7.     // Use this for initialization
    8.     void Start () {
    9.        
    10.         tweenCircleOne = new Tween( CircleOne, circleOneSpeed, new TweenConfig()
    11.             .localRotation(new Vector3(0,0,360))
    12.             );
    13.         tweenCircleTwo = new Tween( CircleTwo, circleTwoSpeed, new TweenConfig()
    14.             .localRotation(new Vector3(0,0,-360))
    15.             );
    16.        
    17.         timeline = new TweenFlow();
    18.        
    19.         timeline.insert(0,tweenCircleOne)
    20.                 .insert(0,tweenCircleTwo);
    21.        
    22.         timeline.setIterations(-1,LoopType.RestartFromBeginning);
    23.         timeline.play();
    24.     }
    if I replace the code above with the below one, i get the desired effect. but i cant control it....... right?
    Code (csharp):
    1. void Start(){
    2. Go.to( CircleOne, circleOneSpeed, new TweenConfig()
    3.             .localRotation(new Vector3(0,0,360))
    4.             .setIterations( -1 ,LoopType.RestartFromBeginning)
    5.             );
    6.         Go.to(CircleTwo,circleTwoSpeed,new TweenConfig()
    7.             .localRotation(new Vector3(0,0,-360))
    8.             .setIterations(-1,LoopType.RestartFromBeginning)
    9.             );
    10. }
     
    Last edited: Nov 15, 2012
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @genius, set your iterations before adding any items to the TweenFlow and it should clear up the issue.
     
  6. geniuscd

    geniuscd

    Joined:
    Aug 10, 2012
    Posts:
    23
    @prime31 I did it .... still looping only 1 time :S
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @genius, use int.MaxValue for your iteration count.
     
  8. twilight

    twilight

    Joined:
    Nov 19, 2012
    Posts:
    6
    Hi prime31,

    I tried exploring your GoSpline, to move object along the path. It was good, but couldn't find method to change speed dynamically along the spline, I was wondering is there any way to solve this problem?

    Got the repro of the problem, I have 5 points, it's not reaching the 5 point for SplineType.CatmullRom, rather the object ends spline on 4th point itself. Previously was using SplineController, integrated newly "GoSpline".

    Can you please give your input? Thanks.
     
    Last edited: Nov 19, 2012
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @twilight, you can adjust the time scale but not the speed. Points will not be reached exactly due to the spline equations being approximations. View the source code to learn how they work.
     
  10. twilight

    twilight

    Joined:
    Nov 19, 2012
    Posts:
    6
    @prime31, thanks for the clarification regarding speed.

    Now able to reproduce the problem, I have 5 points, it's not reaching the 5 point for SplineType.CatmullRom, rather the object ends spline on 4th point itself. Are you saying is this problem due to approximations? Thanks!
     
  11. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @twilight, if it is stopping one node early that is a bug.
     
  12. twilight

    twilight

    Joined:
    Nov 19, 2012
    Posts:
    6
    @prime31, Please find herewith the only code I had for moving object along path:

    //mPath and mTween variable declaration
    _____________________________________________________________________________________________________________________________
    // In Start():
    var vectors = new Vector3[] { new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 10 ), new Vector3( 10, 5, 10 ), new Vector3( 10, 5, 20 ), new Vector3( 10, 5, 30 ) };
    mPath = new GoSpline( vectors );
    mTween = Go.to( _Follower, 6f, new TweenConfig()
    .positionPath( mPath, true, LookAtType.NextPathNode )
    .setIterations( 1 ) );
    _____________________________________________________________________________________________________________________________

    Can you please give your input regarding the solution to this problem?

    Thanks.
     
  13. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @twilight, that is the normal behavior. You have 6 nodes and the Catmull Rom solver can only solve for 5 (n - 1). Add another node if you want the object to end on the ( 10, 5, 30 ) position.
     
  14. Bovine

    Bovine

    Joined:
    Oct 13, 2010
    Posts:
    195
    Hi There

    I decided to look at GoKit, given the mobile friendly claims, but I am somewhat concerned.

    I have some objects I'd like to move around my game world, so I was hoping to create a tween once and re-use it each time, but it looks rather like I cannot do this. I am loathe to be creating new objects every time I want to animate something as before long a GC is inevitable and will eat quite a few MS to complete and create a spike. Is there a way to use the tween API to avoid any unnecessary allocation?

    Previously I was hand tweening, but I was looking to take advantage of the various easing functions without having to code them myself. All suggestions appreciated.

    Thanks
    Bovine
     
  15. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bovine, Tweens are not reusable due to them being tied to the object they are tweening. TweenConfigs are fully reusable though. GoKit puts near nothing on the heap and if you benchmark it you will find that it performs better than any other major tween library available.
     
  16. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Discovered this today - love the path editor!

    I'm trying to get an object to follow a path I created. Here's the code I am using:

    Code (csharp):
    1.  
    2. var path = new GoSpline("GrindRailAPath");
    3.         Go.to( skateboardConObj.gameObject, 4f, new TweenConfig()
    4.             .positionPath( path, true, LookAtType.NextPathNode, gameObject.transform)
    5.             .setIterations( -1, LoopType.PingPong ) ); 
    6.  
    But when I do that, I get the following error, which repeats about one ever half second:
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. PositionPathTweenProperty.prepareForUse ()
    4. Tween.onStart ()
    5. AbstractTween.update (Single deltaTime)
    6. Tween.update (Single deltaTime)
    7. Go.handleUpdateOfType (UpdateType updateType, Single deltaTime)
    8. Go.Update ()
    9.  
    Any ideas?

    Thank you!
     
  17. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @D, check out the path demo scene. It shows a fully functional example using a GoSpline and straight vectors. The code is just:

    Code (csharp):
    1. var path = new GoSpline( "demoRoute" );
    2.  
    3. Go.to( cube, 4f, new TweenConfig()
    4.             .positionPath( path, true, LookAtType.TargetTransform, optionalLookTarget )
    5.             .setIterations( -1, LoopType.PingPong ) );
     
  18. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Prime,

    That was the sample code I used. I reviewed it functioning in the demo scene, copy/pasted it into my scene, and attached a path that I created. I'm not entirely sure what is different about that and mine...

    Though you mention 'Straight Vectors'. When I created my path using the GoDummyPath editor, I noticed it was all curves. Should I be making straight paths rather than curved paths? (And if that's the case, how do I switch between straight and curved?)
     
  19. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @D, straight vectors would be without the path tool like this:

    Code (csharp):
    1. var vectors = new Vector3[] { new Vector3( 0, 1, 1 ), new Vector3( 4, 5, 6 ) };
    2.         var path = new GoSpline( vectors );
    The demo curve was made using the path editor. All paths made by the editor are just straight lines. The is the solver used that gives them their actual curves.
     
  20. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Ok, and I'm presuming that solver exists within your code already, or is that something we need to add?

    Also, in my code above - what would the NullReferenceExceptionObject be referencing in the error? There are a handful of objects in use there and I'm not sure which it is referring to, as reviewing my code and dumping things out all the objects exist.
     
  21. db82

    db82

    Joined:
    Mar 14, 2012
    Posts:
    24
    Hi

    Sometimes when I stop my project running in the Unity Editor, I get the following error:

    "Some objects were not cleaned up when closing the scene"

    And once the editor has stopped, I have an extra GoKit object in the Hierarchy. If this happens a few times without me noticing I can get 3 or 4 GoKit instances in the Hierarchy that need manually deleting.

    Any ideas?

    Thanks
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @db82, fetch the latest from GitHub for a workaround.
     
  23. db82

    db82

    Joined:
    Mar 14, 2012
    Posts:
    24
    Will give it a go cheers

     
  24. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    When using the path editor, is there any way to force any of the values of a node to be what you want? In my situation, I am using an orthographic camera, and want to draw some paths, but whenever I add a node to the curve, the z value is not zero, nor can I ever get it to be zero. Is there a way to force new nodes to have their z values set to 0?
     
  25. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helios, the "show node values" section shows all nodes and lets you edit them.
     
  26. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I've tried doing this, but it does not let me change the values. I can highlight the fields, but can't actually modify anything. I'm using Unity 4.0.0f7.

    EDIT: It will let me outright delete a value, but typing in any number does nothing. When I delete, then focus out of the field, it sets itself to 0. Weird.
     
    Last edited: Dec 19, 2012
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helios, it might require modification for U4. We haven't updated our projects yet so if you make the necessary modifications feel free to send a pull request.
     
  28. Madrayken

    Madrayken

    Joined:
    Mar 14, 2009
    Posts:
    24
    Hi guys!

    Your library has allowed me to do something I've been trying to do for ages now: move a character along a dynamically created path at a constant speed. Excellent. Thanks so much!

    A quick question about a not-so-common requirement. I have an object near a spline, but not actually on it. How would I best find out the nearest % location to snap it to (without doing a bonkers binary search!)?
     
  29. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @madrayken, that is a slightly tricky one. You can start by finding the nearest two nodes which should be pretty fast unless you have thousands of them. Once you have the two nodes you can figure out how far along them you are (between 0 - 1 where 0 is at the first node and 1 is at the second). You can then use that info to get the nearest point on the spline to the current location. That should be fast and pretty accurate.
     
  30. Next Beat Games

    Next Beat Games

    Joined:
    Dec 18, 2012
    Posts:
    7
    Hello. I would like to migrate from iTween to GoKit. I would like to be able to utilize the sharedMaterial for an iTween.ColorTo call because now it will create a new instance of the material to change the colors. Can GoKit access and modify the sharedMaterial for a tween?
     
  31. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @next, GoKit doesn't care of the material is the sharedMaterial or a dupe. It is fully customizable and can animate anything that is a property.
     
  32. Next Beat Games

    Next Beat Games

    Joined:
    Dec 18, 2012
    Posts:
    7
    than in that case, I think I shall look into purchasing
     
  33. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @next, there isn't anything to purchase. GoKit is free and open source.
     
  34. db82

    db82

    Joined:
    Mar 14, 2012
    Posts:
    24
    Hi Prime31

    Stopping the editor while a tween chain is running causes the following error:


    NullReferenceException: Object reference not set to an instance of an object
    Go.removeTween (.AbstractGoTween tween) (at Assets/Plugins/GoKit/Go.cs:307)
    AbstractGoTween.destroy () (at Assets/Plugins/GoKit/base/AbstractGoTween.cs:191)
    TitleScreenMenuScript.OnDestroy () (at Assets/Scripts/UI/Menus/TitleScreenMenu/TitleScreenMenuScript.cs:137)

    I'm using the latest version, any way to fix this?

    Thanks!
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @db82, it's hard to say. What is on line 307 of Go.cs? I don't know what version you are using to I cant make a suggestion for sure. If you are on the latest version it could be a Destroy race condition that can be remedied by adding the following line right before line 307 inside the #if UNITY_EDITOR block:

    Code (csharp):
    1. if( _instance != null  _tweens != null )
     
  36. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    I can't seem to figure out how to enable the GoSplineType.StraightLine on my tween from code. Anyone knows?

    Figured it out, have to set it on the path, not on the tween.
     
    Last edited: Jan 15, 2013
  37. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    I was seeing the same issue. If I stop the editor while a tween is playing I'd get the error. That if-check fixed the issue. Could you please add that to the source. :)

    -Jeff
     
  38. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jeff, it is already in the source.
     
  39. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    In case anyone missed it, GoKit now has a baby sister: GoKitLite. GoKit has a slightly different focus than GoKitLite. It is highly customizeable and can tween anything at all with a full object oriented approach to things. GoKit has all kinds of nifty features like internal support chains, flows and full tween control in real time that arent ever going to be in GoKitLite. GoKitLite is made for folks who want a really easy API and just want to tween stuff now without much thought or control.

    You can get GoKitLite in the usual location on GitHub: https://github.com/prime31/GoKitLite
     
  40. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    Prime31,

    I just want to trigger a method as soon as a tween completes it's execution. I have seen a lot of your tutorials regarding Actions (lamda), hence I was wondering if there is any API call of that sort on your GoKit.

    Thank you.

    ___________________________________________________________________________________________________________________________
    I did post the same a while ago on this thread. I did not get lucky enough for someone to reply hence I am reposting my question.
    http://forum.unity3d.com/threads/162039-Can-a-tween-in-GoKit-trigger-an-event-on-it-s-completion
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @karsnen, Tweens have completion handlers. See the demo scene, documentation or video tutorial for examples.
     
  42. Ripline

    Ripline

    Joined:
    Jul 22, 2012
    Posts:
    3
    Question...

    Debugging some things, I noticed that none of our Chain tweens were ever getting removed from the list of tweens. I had assumed that this would happen by default, but when I look at the code I see that there's nothing setting autoRemoveOnComplete for AbstractGoTweenCollection objects. When I add that, everything cleans up as I would expect.

    Is that an unintentional thing or is there some reason why we shouldn't set that boolean automatically?
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ripline, that is intentional so that chains/flows can be played forward/backward/etc
     
  44. Ripline

    Ripline

    Joined:
    Jul 22, 2012
    Posts:
    3
    Thanks for the quick reply.

    One more... We were having a problem with some chains we were making not getting destroyed when we called killAllTweensWithTarget (with traverseCollections set to true). We create a simple chain with a single target, play it, and then call killAllTweensWithTarget using that target.

    Debugging that, the list of tweens is getting the GoTweenChain added to it. But, when killAllTweensWithTarget calls tweensWithTarget, the list comes back with the GoTweens and not the GoTweenChain, so the removeTween calls keep failing because those GoTweens are not in _tweens (just the GoTweenChain is).

    End result is a bunch of debug log spew (and over-iteration because the destroyed GoTweenChain is still in the list of tweens for a while).

    Are we misusing the features somehow here?
     
  45. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ripline, dig through the source and see what you find. We made GoKit open source so that the community could get involved and "take the reigns" so to speak on the project.
     
  46. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    Hello,

    I was wondering whether it is possible to know whether a tween is running or not? Something like a boolean return. My purpose for that is, I have my camera tween a lot of time. At certain time, I want to pause and resume a tween. Thats why.

    Thank you,

    Karsnen.
     
  47. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @karsnen, check the docs and the source to learn how the lib works. There are many ways to do that including listening to the completion event.
     
  48. jptsetung

    jptsetung

    Joined:
    Jan 12, 2013
    Posts:
    51
    Hi, I'm trying to use GoKit for just delaying a function call.

    Trying this with no luck (no erors but method is not called)

     
  49. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jp, why don't you do it properly with either Invoke or a coroutines? See Unitys docs for more info.
     
  50. jptsetung

    jptsetung

    Joined:
    Jan 12, 2013
    Posts:
    51
    I didn't find a simple way to do this (I'm quite new to C#). I like being able to do this in one line, all solutions require a couple of lines.
    So is it possible with GoKit? What problem do you have about doing it with GoKit, is it less performant than with another proper way?