The object of type 'Canvas' has been destroyed but you are still trying to access it.

Hi,

I’m getting this MissingReferenceException “The object of type ‘Canvas’ has been destroyed but you are still trying to access it.” whenever I’ve loaded a certain scene for the second time. It works fine the first time, but exiting and reloading the scene breaks it. Nothing is set to be persistent across scenes except for a singleton GameManager and NetworkManager.

The script is part of the GUI prefab and is used to enable the post game canvas. It is attached to the PostStatsCanvas object:

    private Canvas          _canvas;

void Start()
        {
        ...
            _canvas         = GetComponent<Canvas>();
            _canvas.enabled = false;
       ...
        }

    public void OnPostMatch(Player winner)
        {
            _canvas.enabled = true;
        }

This is basically all it does other than generating some text, and it throws the exception when I try to enable the canvas whenever I’ve exited and reloaded the match scene more than once. It’s like it’s keeping the reference from the previous time the scene was loaded or something. Nothing else in the MatchGUI object has this problem, even though they all reference other parts of the prefab. Any ideas as to what could be causing this would be greatly appreciated.

Turns out I never unsubscribed an event. >.<