Unsolvable error
« on: May 07, 2015, 02:47:19 PM »
Hi there,

In our project we've been working with hotween but we changed to dotween for more efficiency and optimisation. Actually everything is going fine but just a single problem, a warning (which is an error when not set to safety mode) that happens when we destroy a gameobject on which several related tweens were running).

The code that controls the destruction of this game object is unique (its the only place where it can happen and when it is handled). But in some cases, at destroy we get this warning turning around a null callback in the DOTween stack. Here it is :

Code: [Select]
DOTWEEN :: An error inside a tween callback was silently taken care of > The object of type 'Transform' 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.Debug:LogWarning(Object)
DG.Tweening.Core.Debugger:LogWarning(Object) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/Debugger.cs:26)
DG.Tweening.Tween:OnTweenCallback(TweenCallback) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:265)
DG.Tweening.Tween:DoGoto(Tween, Single, Int32, UpdateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:244)
DG.Tweening.Core.TweenManager:Update(UpdateType, Single, Single) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:390)
DG.Tweening.Core.DOTweenComponent:Update() (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:50)

At the gameobject's destruction we kill the tweens running on the gameobject => DOTween.Kill(gameObject) who is supposed to kill all the tweens related to it, even in children ?! Because in HOTween we had to specify if it does include the tweens running on children or not, this feature doesn't exist anymore in DOTween.

We actually added another tween kill control in the OnDestroy Event of the gameObject to make sure that all the running tweens get killed before destruction :

Code: [Select]
void OnDestroy()
    {
        DOTween.Kill(transform);
        DOTween.Kill(gameObject);
        foreach (Transform child in transform)
        {
            DOTween.Kill(child);
        }
    }

But the warning is still here ! Any knowledge about this issues or are we missing something around ?

Thank you for your answers.

Re: Unsolvable error
« Reply #1 on: May 07, 2015, 04:52:59 PM »
Hi again,

I just want to say that we kind of resolved the problem by delaying the destroy of the gameobject (we just disable it at first and then destroy after a reasonable amount of time) but it would be great if I could have the answers for the different questions I asked

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Unsolvable error
« Reply #2 on: May 08, 2015, 10:37:14 AM »
Hi!

Apologies for the late answer. I posted a warning on Unity Forums, that this week I will be slow to support because of special circumstances.

First of all, all static methods that accept a "target" filter don't work on a gameObject basis, but require the true target you used. For example:

Code: [Select]
// A transform tween
myTransform.DOMoveX(2, 1);
// is killed like this
myTransform.DOKill();
// or like this
DOTween.Kill(myTransform);
// but not like this
DOTween.Kill(myTransform.gameObject);

To kill all tweens on all children your approach is correct (you can scrap the gameObject filter), but it will kill only the tweens that have the main transform or a child transform as a target, and not, for example, tweens that are active on a material. If you still have a callback being fired, it means that you must have some other non-transform tween firing it (or maybe a tween with the same callback that has a completely different transform as a target?). If you're unsure, you could always give an ID to all the tweens you create on a gameObject (and just so you know, you can also use the gameObject itself as an ID), like this:
Code: [Select]
transform.DOMoveX(2, 1).SetId(transform.gameObject);and then you can do:
Code: [Select]
DOTween.Kill([font=Verdana][size=2px]transform.gameObject[/size][/font]);
Cheers!

Re: Unsolvable error
« Reply #3 on: May 11, 2015, 02:52:02 PM »
Hi there !

Thank you for your answer ! Those informations were really helpfull :)