title: Unity is throwing an UnassignedReferenceException during runtime even after reference has been set
body: <p>I'm currently working on a script for a basic pause menu. The script is passed two <code>GameObject</code>s through the inspector, each being a different menu, and alternates between setting each object as enabled while setting the other as disabled. The code had worked fine before I moved it to a different script while restructuring my codebase. The script still executes properly, but each time I perform the operation Unity throws an <code>UnassignedReferenceException</code>, telling me to set the reference to the <code>HUD</code> in the inspector. The reference is clearly set and the operation is being performed, but the error is still thrown. I have checked for other instances of the script, and none are present.</p>
  <p>Here is the full script in question:</p>
  <pre><code>public class GameMenuHandler : MonoBehaviour
  {   
      private bool paused;
  
      [SerializeField] private GameObject HUD;
      [SerializeField] private GameObject pauseMenu;
  
      void Start()
      {   
          SubscribeMethodsToEvents();
      }
      
      public void RestartLevel()
      {   
          String scene_name = SceneManager.GetActiveScene().name;
          SceneManager.LoadScene(scene_name);
      }
  
      public void ExitToMainMenu()
      {
          SceneManager.LoadScene(&quot;MainMenu&quot;);
      }
  
      public void TogglePauseMenu()
      {
          paused = !paused;
          if (paused)
          {
              HUD.SetActive(false);
              pauseMenu.SetActive(true);
              Time.timeScale = 0f;
          }
          else
          {
              HUD.SetActive(true);
              pauseMenu.SetActive(false);
              Time.timeScale = 1f;
          }
      }
  
      void SubscribeMethodsToEvents()
      {
          GameEvents.current.onEscapeKeyPress += TogglePauseMenu;
      }
  
      void UnsubscribeMethodsFromEvents()
      {
          GameEvents.current.onEscapeKeyPress -= TogglePauseMenu;
      }
  
      void OnDestroy()
      {
          UnsubscribeMethodsFromEvents();
      }
  }
  </code></pre>
  <p>Here is the inspector view of the script:</p>
  <p><a href="https://i.stack.imgur.com/cEaDO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cEaDO.png" alt="enter image description here" /></a></p>
  <p>Here is the console after the operation had been performed (successfully) numerous times:</p>
  <p><a href="https://i.stack.imgur.com/0J7gr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0J7gr.png" alt="enter image description here" /></a></p>