Author Topic: BUG - UITweens  (Read 6461 times)

cbartlett

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 43
    • View Profile
BUG - UITweens
« on: April 12, 2013, 10:04:15 AM »
Bug 1) If a animation curve is set on a tween where the curve has multiple slopes (Going Up then down) when Reset() is called the mFactor is set to 1 instead of 0 because the mAmountPerDelta is decreasing.

Bug 2) Connect the eventReceiver and callWhenFinished and enable.  When Reset()/Play() are called the callWhenFinished is fired again because the mStartTime is the old one.

These occur for me because I am using the tweens to fire off other events basically using them as an animation chain.  Then later firing them off again.  Example of bug one, create a label where you want it to fade and out controlled by an animation curve.  This causes a problem when you attempt to Reset() and Play() again.  In the similar fashion the callback will be fired at the incorrect time.

I have change the Play() and Reset() as follows however I realized that this functionality is used for other purposes and may affect how that works but offering it a a possible solution.

  1.         /// <summary>
  2.         /// Manually activate the tweening process, reversing it if necessary.
  3.         /// </summary>
  4.  
  5.         public void Play (bool forward)
  6.         {
  7.                 // Set the start time based on when Play is called
  8.                 mStartTime = Time.realtimeSinceStartup + delay;
  9.                 mAmountPerDelta = Mathf.Abs(amountPerDelta);
  10.                 // set the mAmountPerDelta based on the direction
  11.                 if (!forward)
  12.                 {
  13.                         mAmountPerDelta = -mAmountPerDelta;
  14.                         mFactor = 1;
  15.                 }
  16.                 else
  17.                 {
  18.                         mFactor = 0;
  19.                 }
  20.  
  21.                 enabled = true;
  22.         }
  23.  
  24.         /// <summary>
  25.         /// Manually reset the tweener's state to the beginning.
  26.         /// </summary>
  27.  
  28.         public void Reset() {
  29.                 mFactor = 0;  // not based on the direction in which was going but simply set to the beginning.
  30.                 Sample(mFactor, false);
  31.         }
  32.  

Thoughts?

PapaWhiskey

  • Guest
Re: BUG - UITweens
« Reply #1 on: April 12, 2013, 11:35:46 AM »
just stumbled on this bug yesterday for us as well...

same situation...i have position tweens set up for some tutorial panels...panel slides in, user presses next, i slide the panel out and slide a new one in...on subsequent return to the same screen, regardless of "play()" or "reset()" the tweens arent working

Abyss_DoD

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: BUG - UITweens
« Reply #2 on: April 14, 2013, 10:40:18 PM »
I think I may have a similar or possible same bug as you guys:

What I am trying to do:
I have a simple setup, a label that has a simple TweenAlpha on it. The base settings are setup so it will pingpong between 1 to 0, essentially blinking the label on and off smoothly over the course of 1 second. When I hit a certain key, I want it to take it's current value and set the TweenAlpha up so that it goes from current alpha value back to 1 over the course of a certain amount of time. For example possibly over 4 seconds ( this was just for testing ).

What happens:
It seems to be failing on the reverse trip of TweenAlpha, if I run FinalAlpha() during the forward direction of the TweenAlpha, it fires off perfectly, if I ask it to run FinalAlpha() during the reverse direction of the TweenAlpha, it immediately completes my new settings in 0 seconds. I had tried to detect which direction the TweenAlpha was going when I wanted to run FinalAlpha(), but no matter if I did, and tried to .Toggle() the TweenAlpha or not, I can't get the behavior to work when the TweenAlpha was in the middle of the reverse direction when I called FinalAlpha(). Any ideas??

I am using the following code:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PressStart : MonoBehaviour {
  5.  
  6.     private UILabel label;
  7.     private TweenAlpha alpha;
  8.     private bool startPressed = false;
  9.     private bool ranFinalAlpha = false;
  10.     private float startTime = 0.0f;
  11.     private float endTime = 0.0f;
  12.  
  13.     // Use this for initialization
  14.     void Start() {
  15.         label = gameObject.GetComponent<UILabel>();
  16.         alpha = gameObject.GetComponent<TweenAlpha>();
  17.         Debug.Log(string.Format("Label: {0}", label.name));
  18.         Debug.Log(string.Format("ColorTint: {0}", label.color));
  19.         scale.Reset();
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update() {
  24.         if (Input.GetButton("Win 360 Pad1 Start") && !startPressed) {
  25.             startPressed = true;
  26.             Debug.Log("Pressed Start button");
  27.         }
  28.  
  29.         if (startPressed) {
  30.             if (!ranFinalAlpha) {
  31.                 FinalAlpha();
  32.             }
  33.         }
  34.     }
  35.  
  36.     void FinalAlpha() {    
  37.         startTime = Time.time;
  38.         ranFinalAlpha = true;
  39.         Debug.Log("Entered final alpha");
  40.         float currentAlpha = alpha.alpha;
  41.         Debug.Log(string.Format("Alpha when called: {0}", currentAlpha));
  42.         alpha.from = currentAlpha;
  43.         alpha.to = 1.0f;
  44.         alpha.duration = 4.0f;
  45.         alpha.style = UITweener.Style.Once;
  46.         alpha.callWhenFinished = "CalledToFinish";
  47.         alpha.eventReceiver = gameObject;
  48.  
  49.         alpha.Reset();
  50.  
  51.         alpha.Play(true);
  52.     }
  53.  
  54.     void CalledToFinish() {
  55.         endTime = Time.time;
  56.         Debug.Log("Was called at finish!");
  57.         Debug.Log(string.Format("Elapsed Time: {0}", endTime - startTime));
  58.     }
  59.  
  60.     void OnGUI() {
  61.         GUILayout.BeginArea(new Rect(0, 0, 330, 700));
  62.         GUILayout.Label(string.Format("Current Alpha: {0}", alpha.alpha));
  63.         GUILayout.EndArea();
  64.     }
  65. }
  66.  

cbartlett

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 43
    • View Profile
Re: BUG - UITweens
« Reply #3 on: April 15, 2013, 10:02:03 AM »
Yep sounds like the exact same problem. 
I would use the code I posted in the UITween.  It changes some of the behavior of the tween but for the most part I consider it a better behavior that its current and more predictable. 

Other thoughts, IF you are wanting a ping-pong that lasts a specific amount of time, I have turned to the animation curve and actually created the curve myself.  Then set the entire duration.  So if I needed a ping pong that lasted 3 secs, I set the duration and then how every many pulses I needed.  But just a thought.

Hope some of this helps.

Abyss_DoD

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: BUG - UITweens
« Reply #4 on: April 15, 2013, 04:34:04 PM »
Good point, I should probably switch over to using my own anim curve, and just let it play forward forever ( loop mode ), but to do it perfectly, unless his loop code already knows how to handle the anim curve properly, you would end up with 2 time slices with the same data ( first key, last key values ) that could cause a pause, my hope is that it is already being handled. Either way I can work past my issue.

I do have a question, I am doing a .Reset() in my code before doing a .Play() it seems like it is required for what I am trying to do ( change values of the TweenAlpha and play that new data ), but I wanted to make sure it was strictly required. Thanks again!

cbartlett

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 43
    • View Profile
Re: BUG - UITweens
« Reply #5 on: April 15, 2013, 04:53:01 PM »
I also call it but as I posted the code, I have modified the Reset and the Play.  In my version I don't have to call Reset because I am setting the mFactor to the correct value depending on the direction you would want it to play.

Otherwise, yes you should call reset prior to play to set the mFactor...

Abyss_DoD

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: BUG - UITweens
« Reply #6 on: April 16, 2013, 11:58:57 PM »
Ok so I was able to work past my issue, I would love to see this get fixed in a release by the author. Thanks again CBartlett.