Author Topic: Tweens not working correctly on low framerates - Not scaling from 0  (Read 7603 times)

dadrester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Hi,

We're having problems with some tweens not playing correctly or ending in odd places at low framerates. None of our tweens scale to or from 0, and some of the problems happen on tween position as well as tween scale, where a sprite/game object won't end in it's intended resting position. It's a similar bug to the one seen in Fallout Shelter where sliding UI elements sometimes finish before being in the correct "To" position so appear over the top of one another.

Most are set to ignore TimeScale (though we've seen the same issue happen with or without TimeScale being ignored). Any help or pointers to the cause would be great.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweens not working correctly on low framerates - Not scaling from 0
« Reply #1 on: August 08, 2016, 06:02:16 PM »
Can you create a repro case for me to have a look at? You can force low framerate just by adding something like Thread.Sleep(200) to an Update() function of a script.
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         void Update ()
  6.         {
  7.                 System.Threading.Thread.Sleep(200);
  8.         }
  9. }
  10.  
I tried it on my end, and everything worked as expected every time.

P.S. Repro case can be submitted via email to support [at] tasharen.com

dadrester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweens not working correctly on low framerates - Not scaling from 0
« Reply #2 on: August 15, 2016, 09:42:38 AM »
Will do. Just getting ready for Gamescom, but will do one when I get back.

dadrester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Tweens not working correctly on low framerates - Not scaling from 0
« Reply #3 on: September 19, 2016, 09:11:22 AM »
I don't think the problem is framerate dependent on further investigation. We run a script on some NGUI tweens that resets them OnEnable. For the most part these work, however they occasionally go wrong. I've noticed the transforms and rotations are correct for the objects themselves, however the UISprite isn't always updating correctly (to the correct position/scale). Below is the script we use that calls the reset function. Just wondering if this looks right to you, or if we're missing something?


  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// Reset tween children on enable.
  5. /// </summary>
  6. public class ResetChildrenTweensOnEnable : MonoBehaviour {
  7.         [SerializeField]
  8.         bool m_ResetChildren = true;
  9.  
  10.         [SerializeField]
  11.         public bool m_AutoPlayOnEnable = true;
  12.         //tweens
  13.         private UITweener[] m_tweens;
  14.  
  15.         /// <summary>
  16.         /// Gets all the tweeners.
  17.         /// </summary>
  18.         void Start () {
  19.                 if (m_tweens == null)
  20.                 {
  21.                         if(m_ResetChildren)
  22.                                 m_tweens = GetComponentsInChildren<UITweener>();
  23.                         else
  24.                                 m_tweens = GetComponents<UITweener>();
  25.                 }
  26.         }
  27.        
  28.         /// <summary>
  29.         /// Reset all the tweens.  Made this function public so other script could call this function manually to reset all the tweeners.
  30.         /// </summary>
  31.         public void OnEnable () {
  32.                 if (m_tweens == null)
  33.                 {
  34.                         Start();
  35.                 }
  36.                 for (int i = 0; i < m_tweens.Length; i++)
  37.                 {
  38.                         if(m_AutoPlayOnEnable)
  39.                         {
  40.                                 m_tweens [i].ResetToBeginning();
  41.                                 m_tweens [i].enabled = true;
  42.                                 m_tweens [i].PlayForward();
  43.                         }
  44.                 }
  45.         }
  46.  
  47.         /// <summary>
  48.         /// Resets the tween.
  49.         /// </summary>
  50.         public void ResetTween()
  51.         {
  52.                 if (m_tweens == null)
  53.                 {
  54.                         Start();
  55.                 }
  56.  
  57.                 for (int i = 0; i < m_tweens.Length; i++)
  58.                 {
  59.                         m_tweens [i].ResetToBeginning();
  60.                         m_tweens [i].enabled = true;
  61.                         m_tweens [i].PlayForward();
  62.                 }
  63.         }
  64. }
  65.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tweens not working correctly on low framerates - Not scaling from 0
« Reply #4 on: September 20, 2016, 01:10:48 AM »
I would change how your OnEnable and Start work. You have it like this:
  1. void OnEnable () // Executed before Start()
  2. {
  3.     // call Start's code
  4. }
  5.  
  6. void Start ()
  7. {
  8.     // Do stuff
  9. }
  10.  
It should instead be this:
  1. bool mStarted = false;
  2.  
  3. void Start ()
  4. {
  5.     mStarted = true;
  6.     // <cache GetComponents here>
  7.     DoStuff();
  8. }
  9. void OnEnable () { if (mStarted) DoStuff(); }
  10.  
  11. void DoStuff ()
  12. {
  13.     // Reset and play tweens
  14. }
This will ensure that your tweens won't start playing in OnEnable, but will instead always wait for Start() to complete, thus ensuring that other Awake and OnEnable calls get executed first. NGUI uses this approach everywhere: just search for "mStarted", you will find a lot of them.