Open TouiSoraHe opened 4 years ago
My team is running into the same issue. In our case, it was a little obscure since we have tween A which disables a GameObject. When the GameObject is disabled, all tweens should skip ahead (Complete with callbacks), which works fine when the GameObject is disabled from a regular call, but not if called from within tween A.
Here is my reproduction script, just put it on any Transform in the scene to see it in action:
using DG.Tweening;
using UnityEngine;
public class Test : MonoBehaviour
{
private Sequence scaleTween;
private void Start()
{
// Tween that should be killed/completed with onComplete callback.
scaleTween = DOTween.Sequence();
scaleTween.Append(transform.DOScale(Vector3.one * 5, 15));
scaleTween.onComplete += () => Debug.Log("ScaleTween Complete.");
// Some other tween that disables a GameObject and should kill/skip/complete the scale tween.
var moveTween = DOTween.Sequence();
moveTween.Append(transform.DOMove(new Vector3(5, 0f, 0f), 5));
moveTween.AppendCallback(OnMoveTweenCallback);
moveTween.Append(transform.DOMove(new Vector3(10f, 0f, 0f), 10));
moveTween.onComplete += () => Debug.Log("MoveTween Complete.");
}
private void OnMoveTweenCallback()
{
Debug.Log("OnMoveTweenCallback");
gameObject.SetActive(false);
// Here the scale tween should skip to the end
// and invoke the log statement above "ScaleTween Complete."
// But in reality, the scaleTween scales to the final end scale, but onComplete is not called.
scaleTween.Complete(withCallbacks: true);
}
}
How can I work around this issue? I believe this will be a common thing where some tweens are running, and if they are at a midpoint callback and other tweens are still running, these other tweens must be skipped.
@chrisyarbrough My solution is to encapsulate Dotween,like:
SimpleFramework.Util.OnUpdate(tween,function()
if info.OnUpdate then
info.OnUpdate()
end
if AnimationModule.IsComplete(tween) == true and info.OnComplete then
info.OnComplete()
end
end)
OnComplete of tween2 never called,Because TweenManager.isUpdateLoop == true