Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.35k stars 350 forks source link

Dotween seems to be persisting even after Destroying it. #403

Closed MewEight closed 4 years ago

MewEight commented 4 years ago

So i have a scene, that swaps a sprite when its attacked. On first scene, it works fine. But after doing

    internal static void ReloadScene()
    {
        DOTween.Clear(true);
        DOTween.ClearCachedTweens();

        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }

And doing the same action will cause an error to occur. Below is a code snippet of how i trigger the sprite swap. reachAction is basically the one that does spriteRend.sprite = newSprite


    public void ShootAt(Vector3 start, Vector3 end, float duration, System.Action reachAction)
    {
        ProjectileScript newProjectile = _projectilePool.GetFromPool();
        newProjectile.transform.position = start;
        newProjectile.transform.DOMove(end, duration).SetEase(Ease.Linear).OnComplete(() => 
        {
            reachAction?.Invoke();
            _projectilePool.Pool(newProjectile);
        });
    }

Full log.

MissingReferenceException: The object of type 'SpriteRenderer' 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.
TileScript.Remap () (at Assets/_Scripts/Tile/TileScript.cs:38)
TileManager.OnEnemyDeath (UnityEngine.Vector2Int obj) (at Assets/_Scripts/Managers/TileManager.cs:689)
EnemyManager.RemoveEnemy (EnemyScript es) (at Assets/_Scripts/Managers/EnemyManager.cs:169)
EnemyScript.TakeDamage (System.Int32 damage) (at Assets/_Scripts/Enemy/EnemyScript.cs:39)
EnemyManager.DamageEnemy (UnityEngine.Vector2Int point, System.Int32 v) (at Assets/_Scripts/Managers/EnemyManager.cs:153)
AttackManager+<>c__DisplayClass15_0.<Attack>b__0 () (at Assets/_Scripts/Attack/AttackManager.cs:87)
ProjectileManager+<>c__DisplayClass7_0.<ShootAt>b__0 () (at Assets/_Scripts/Managers/ProjectileManager.cs:33)
DG.Tweening.Tween.OnTweenCallback (DG.Tweening.TweenCallback callback, DG.Tweening.Tween t) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:302)
DG.Tweening.Tween.DoGoto (DG.Tweening.Tween t, System.Single toPosition, System.Int32 toCompletedLoops, DG.Tweening.Core.Enums.UpdateMode updateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:276)
DG.Tweening.Core.TweenManager.Update (DG.Tweening.UpdateType updateType, System.Single deltaTime, System.Single independentTime) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:490)
DG.Tweening.Core.DOTweenComponent.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:74)
MewEight commented 4 years ago

Found my issue. Its because i am using a static event that caused this problem to happen.