Gameobject referenced is getting deleted while restarting scene
13:45 28 May 2026

I am trying to create a Quit Poup in my game which contains below options My Quit Popup image

When I clicked on Restart button my Scene get restart. However after restarting the scene, when i am trying to reload Quit Popup i am not able to do so.
It is happening because after restart, reference of my QuitPopup is getting cleared from my unity script.
Following are my code

Game Controller.cs

public class   GameController : MonoBehaviour
{
 [Header("QuitPopup")]
 public QuitPopupController quitPopup;
 void Update()
  {

        if (Input.GetKeyDown(KeyCode.Escape))
            quitPopup.ExecuteQuitPopup();
  }
}

QuitPopupController.cs


public class QuitPopupController : MonoBehaviour
{
    
    public GameObject popupPanel;
    public static QuitPopupController Instance { get; private set; }

    void Start()
    {
        Instance = this;
    }

    void Update()
    {
      
    }

    private void Awake()
    {
        Instance = this;
    }

    public void ExecuteQuitPopup()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (GameController.Instance != null && GameController.Instance.IsAnimationRunning) return;

            if (popupPanel != null && popupPanel.activeSelf)
                ResumeGame();
            else
                Show();
        }
    }

    public void Show()
    {
        if (popupPanel != null)
        {
            popupPanel.SetActive(true);
            Time.timeScale = 0f;
        }
    }

    public void ResumeGame()
    {
        if (popupPanel != null)
        {
            popupPanel.SetActive(false);
            Time.timeScale = 1f;
        }
    }

    public void RestartGame()
    {
        Time.timeScale = 1f;
        SceneManager.LoadScene("GameScene");
    }

    public void QuitToMainMenu()
    {
        Time.timeScale = 1f;
        SceneManager.LoadScene("MainMenu");
    }
}





Not able to understand why this happening. Any advice will really helpful.

Thanks in advance.

c# unity-game-engine