Search Unity

iTween.Pause throwing error after Unity update.

Discussion in 'Scripting' started by MWMusker, Oct 1, 2012.

  1. MWMusker

    MWMusker

    Joined:
    Apr 29, 2011
    Posts:
    45
    So I've opened a project that hasn't had any code development in a while after updating unity recently, and I've run in to some odd behavior.

    Essentially we've got an object on an iTween spline that controls our camera for a sort of on-rails game. We set this up using the iTween Event editor plugin and simply flagging our MoveTo event to play automatically.

    As part of collisions with objects we call iTween.Pause() while we execute some "bounce" code before calling iTween.Resume;

    Everything has been working fine for a while but recently after upgrading to Unity 3.5.5 iTween.Pause(); Throws the following MissingReferenceException after the level is reloaded via Application.Loadlevel

    Basically, the game works as well as it always has until our first "game over" after the call to Application.LoadLevel then spits an error originating from iTween.cs:

    Code (csharp):
    1.  
    2. Log in file: Assets/Plugins/iTween.cs at line: 6188
    3.  
    4. MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    5. Your script should either check if it is null or you should not destroy the object.
    6. UnityEngine.GameObject.GetComponents (System.Type type) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:63)
    7. iTween.Pause (UnityEngine.GameObject target) (at Assets/Plugins/iTween.cs:6188)
    8. iTween.Pause () (at Assets/Plugins/iTween.cs:6267)
    9. LloydCollisionAndHealth+$GotHit$18+$.MoveNext () (at Assets/Prototyping_Systems/Scripts/LloydCollisionAndHealth.js:128)
    10. UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
    11. LloydCollisionAndHealth:OnCollisionEnter(Collision) (at Assets/Prototyping_Systems/Scripts/LloydCollisionAndHealth.js:83)
    12.  
    The line referenced in my code is literally simply iTween.Pause(); Which worked flawlessly through multiple Application.Loadlevel uses until very recently after updating unity.

    For reference here's the problem function in iTween at that line:

    Code (csharp):
    1.  
    2. /// <summary>
    3.     /// Pause all iTweens on a GameObject.
    4.     /// </summary>
    5.     public static void Pause(GameObject target){
    6.         Component[] tweens = target.GetComponents(typeof(iTween));
    7.         foreach (iTween item in tweens){
    8.             if(item.delay>0){
    9.                 item.delay-=Time.time-item.delayStarted;
    10.                 item.StopCoroutine("TweenDelay");
    11.             }
    12.             item.isPaused=true;
    13.             item.enabled=false;
    14.         }
    15.     }
    16.  
    Nothing in the scene has any flags to avoid destruction on scene changes, and this all worked just fine before updating my unity version. Any Ideas?
     
  2. MWMusker

    MWMusker

    Joined:
    Apr 29, 2011
    Posts:
    45
    After some further testing, it seems this error is only thrown every other time the scene is reloaded.

    Basically

    Initial load: working
    First reload: error
    Next reload: working
    Next reload: Error

    and so on.
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    All I can guess at is that you have a var, likely a true or false, 1 or 0 situation that does not reset correctly. This just happened to me.
     
  4. MWMusker

    MWMusker

    Joined:
    Apr 29, 2011
    Posts:
    45
    It actually becoming very unstable in terms of when it works or doesn't. For a while it was a reliable every other time, now I'm getting MREs out of iTween.Stop() as well. It's not an unset bool or anything, and It's extremely odd because it only gets problematic after the level is loaded from within the scene.

    We were using iTween.Stop() to dump all the tweens from the scene to avoid this exact problem before, but it seems its no longer a reliable way of keeping the lib from stubbornly holding on to its object list.

    All of this code executed flawlessly before updating to 3.5.5, but now it seems the argument-free versions of these methods are just getting plain jacked up by Application.LoadLevel
     
  5. PAEvenson

    PAEvenson

    Joined:
    Nov 12, 2009
    Posts:
    47
    I had a huge problem with iTween.Pause() and Resume. I would get random exceptions being thrown and a whole bunch of problems. I ended up sending out a global message to all the objects I need to pause/resume and let them handle setting their itween scripts to paused. I havent seen an issue since. Hope this helps.
     
  6. Ricks

    Ricks

    Joined:
    Jun 17, 2010
    Posts:
    650
    Just got the same problem. iTween.Count shows me 0 and yet it throws this error whenever I try to reload the Level with Application.LoadLevel(). As if iTween still holds a reference to each object it was once attached... any quick solutions?

    Edit: part of the mistake is on my side. I assigned references to GameObjects in a class with static methods but since the class was never refreshed on Application.LevelLoad the references stayed the same through all LevelLoads.

    But it's still not 100% safe and I can only prevent remaining errors when destroying the GameObject - which is OK on loading levels, but I do wonder why all these commands had absolutely no effect:

    // Useless when loading levels, but works during ingame actions.
    iTween.Stop(SomeGameObject)
    iTween.Stop(SomeGameObject, true)
    iTween.StopByName("SomeTweenName");
    iTween.tweens.Clear();

    // Works when loading levels, but must be performed on every GameObject using iTween.
    Destroy (SomeGameObject);
    iTween.Stop ();

    If any of the latter 2 commands is missing it again produces errors.
     
    Last edited: Dec 30, 2013