I am using HOTween and ran into a problem. I am switching between scenes/menu via LoadLevel(0) or LoadLevel(1). Sometimes I also reload the scene via LoadLevel(1) when I am already in level 1.
Now, it looks like HOTweens that I started carry over from scene to scene. That means that I am error messages with callbacks. In my case, this callback tries to access a Transform of a GameObject that no longer exists - naturally, because the Level changed.
I expected all HOTweens to die anyway during a Level transition. Do they? If not, does that mean that I have to store all return values of HOTween Sequences or Tweeners somewhere and kill all those manually before I make a Level change?!
About level loading, yes, you have to manually kill all tweens if their targets become unavailable. HOTween makes a quick check to see if its target is NULL, but with Unity sometimes things become inaccessible but are not yet NULL (like Transforms during a level load).
Anyway, to kill all tweens, you can simply call
HOTween.Kill();
or you can add an ID there to kill only the tweens that were created with a given ID parameter.
About the reasons of this behaviour, they’re simple:
sometimes you have objects that won’t destroy on level loading and you want to continue animating them
making longer checks for inaccessible targets (longer than the quick one HOTween already makes) to determine if it’s NULL, would slow down the engine
By the way, me calling HOTween.Kill() before Application.LoadLevel(…) did not helped.
I did a new singleton class called HOTweenManager, where at Awake I call HOTween.Kill(), and HOTweenManager is first script to execute at startup.
This did the trick.