Unity Itween error

How can this be solved, and what is the problem? error:

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)
iTween.Stop (UnityEngine.GameObject target, System.String type) (at Assets/iTween/Plugins/iTween.cs:6436)
HutongGames.PlayMaker.Actions.iTweenFsmAction.OnExitiTween (HutongGames.PlayMaker.FsmOwnerDefault anOwner) (at Assets/PlayMaker/Actions/iTween/iTweenFsmAction.cs:64)
HutongGames.PlayMaker.Actions.iTweenMoveTo.OnExit () (at Assets/PlayMaker/Actions/iTween/iTweenMoveTo.cs:110)
HutongGames.PlayMaker.FsmState.OnExit ()
HutongGames.PlayMaker.Fsm.ExitState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.Stop ()
HutongGames.PlayMaker.Fsm.OnDisable ()
PlayMakerFSM.OnDisable ()

found where the error is coming from, but i need help to solve it public static void Stop(GameObject target, string type){ Component[] tweens = target.GetComponents(typeof(iTween)); foreach (iTween item in tweens){ string targetType = item.type+item.method; targetType=targetType.Substring(0,type.Length); if(targetType.ToLower() == type.ToLower()){ item.Dispose(); } } }

–

3 Answers

3

I believe this error is called when you destroy an object that is currently using an iTween. iTween isn’t very friendly in this situation, and doesn’t bother to check if the object has been destroyed. I think the only way you can really avoid this is to stop all iTweens on the object that you are destroying. It looks like you’re using Playmaker, so check if there is a premade action that can remove all iTweens on the object. If there is not, you may want to post on the Playmaker forums about this so they can create one for you.

Thanks a lot

–

How can i check if this is null, still not working.

If you're still not working, I had to modify iTween itself to get mine to work. I was not destroying the object the call was on, but StopByName (or in your case, Stop) was breaking anyways. I added a null check to that function in iTween and it fixed my problem.

–

if any one still having this problem in ITween this is my solution:

Edit the ITween.cs File (/Plugins/Pixelplacement/iTween/iTween.cs) At line 6150
public static void StopByName(GameObject target, string name){
//Add This Line
`` if (target == null) return;
Component tweens = target.GetComponents();
foreach (iTween item in tweens){
/string targetType = item.type+item.method;
targetType=targetType.Substring(0,type.Length);
if(targetType.ToLower() == type.ToLower()){
item.Dispose();
}
/
if(item._name == name){
item.Dispose();
}
}
}