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:
Log in file: Assets/Plugins/iTween.cs at line: 6188
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.GameObject.GetComponents (System.Type type) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:63)
iTween.Pause (UnityEngine.GameObject target) (at Assets/Plugins/iTween.cs:6188)
iTween.Pause () (at Assets/Plugins/iTween.cs:6267)
LloydCollisionAndHealth+$GotHit$18+$.MoveNext () (at Assets/Prototyping_Systems/Scripts/LloydCollisionAndHealth.js:128)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
LloydCollisionAndHealth:OnCollisionEnter(Collision) (at Assets/Prototyping_Systems/Scripts/LloydCollisionAndHealth.js:83)
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:
/// <summary>
/// Pause all iTweens on a GameObject.
/// </summary>
public static void Pause(GameObject target){
Component[] tweens = target.GetComponents(typeof(iTween));
foreach (iTween item in tweens){
if(item.delay>0){
item.delay-=Time.time-item.delayStarted;
item.StopCoroutine("TweenDelay");
}
item.isPaused=true;
item.enabled=false;
}
}
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?