Animations are not cleaning up on scene change under certain conditions.

0 votes
asked Oct 4, 2016 in Issue by anthonyioflux (610 points)
edited Oct 4, 2016 by anthonyioflux
MissingReferenceException: The object of type 'AnimatedShadow' 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.
MaterialUI.AnimatedShadow+<SetShadow>c__AnonStoreyBA.<>m__12B () (at Assets/MaterialUI/Scripts/Common/Shadows/AnimatedShadow.cs:84)
MaterialUI.ActionExtension.InvokeIfNotNull (System.Action action) (at Assets/MaterialUI/Scripts/MaterialUtils/Extensions.cs:156)
MaterialUI.AutoTween.EndTween (Boolean callback) (at Assets/MaterialUI/Scripts/Animation/AutoTween.cs:177)
MaterialUI.AutoTween.UpdateTween () (at Assets/MaterialUI/Scripts/Animation/AutoTween.cs:164)
MaterialUI.TweenManager.Update () (at Assets/MaterialUI/Scripts/Managers/TweenManager.cs:163)
Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)

This is happening when the user clicks very fast through UI and the scene is changed after interacting with a button. In our example we have two buttons and a tab view. If you click the one button it moves to the last tab view and swaps with another button that exits the scene on click. If the user clicks the skip button and then the exit button right after, then the TweenManager tries to work with destroyed objects and throws a tween exception or that objects were instantiated in OnDestroy.

commented Oct 17, 2016 by admin (31,720 points)
Hi anthonyioflux,

I've been able to replicate this issue, and will work on fixing it when I can :)

~ Declan.
commented Oct 17, 2016 by anthonyioflux (610 points)
Hi Declan,

It is not a blocking issue though, just something I picked up in the error logs.

Keep up the good work, you have a great product.
commented Oct 24, 2016 by anonymous
I have the same problem when I hide my custom dialog.

1 Answer

0 votes
answered Jan 22, 2018 by Alberto Benavides
Is there any solution to this now?
commented May 22, 2018 by Jeremie Petitjean

Hi, I had this issue because of some custom scene management. 

You can fix it like this. It was because of the callback execution.

From AnimatedShadow.cs

/// <summary>
/// Starts animating a shadow on or off.
/// </summary>
/// <param name="set">If true, animate the shadow on. Otherwise animate it off.</param>
/// <param name="tweenType">The type of tween curve to use. 'Custom' is not supported.</param>
/// <param name="instant">Should the transition be instant and not animate?</param>
public void SetShadow(bool set, Tween.TweenType tweenType, bool instant = false)
    if (gameObject == null) return;

    isVisible = set;

    if (set)

    if (Application.isPlaying && !instant)

        m_Tweener = TweenManager.TweenFloat(f => canvasGroup.alpha = f, () => canvasGroup.alpha, set ? 1f : 0f, 0.5f, 0f, Callback(set), tweenType: tweenType);
        canvasGroup.alpha = set ? 1f : 0f;

private Action Callback(bool set)
    if (!gameObject)
        return () => gameObject.SetActive(set);
        return null;


Welcome to MaterialUI support! Ask us anything :)