UI Toolkit buttons do not work when presssed

I have a small issue with my UI.

Whenever I click a button on my pause menu ui nothing happens even when I hover over the buttons. However, in my main menu scene, the UI works without any problems. Comparing the code side by side they are pretty much identical. I am also using the UI Toolkit for my UI instead of the older UI system.

public class PauseMenuUIDocumentManager : MonoBehaviour
{
   private static VisualElement pauseMenuContainer;
   private Button mainMenuButton;
   private Button settingsButton;
   private Button quitToDesktopButton;

   public static VisualElement PauseMenuContainer
   {
      get => pauseMenuContainer;
      set => pauseMenuContainer = value;
   }

   private void Start()
   {
      var root = GetComponent<UIDocument>().rootVisualElement;

      pauseMenuContainer = root.Q<VisualElement>("Background");

      mainMenuButton = root.Q<Button>("MainMenuButton");
      settingsButton = root.Q<Button>("SettingsButton");
      quitToDesktopButton = root.Q<Button>("QuitToDesktop");
      
      mainMenuButton.clicked += MainMenuButtonOnclicked;
      settingsButton.clicked += SettingsButtonOnclicked;
      quitToDesktopButton.clicked += QuitToDesktopButtonOnclicked;
   }

   private void QuitToDesktopButtonOnclicked()
   {
      Application.Quit();
   }

   private void MainMenuButtonOnclicked()
   {
      Time.timeScale = 1f;
      GameManager.LoadScene("MainMenu");
   }

   private void SettingsButtonOnclicked()
   {
      throw new NotImplementedException("This feature will be implemented later down the line");
   }
}

Here is my game manager script that I use to show the pause menu and to actually pause the game.

if (Input.GetKeyDown(KeyCode.Escape) && gameIsPaused == false && gameCanBeUnPaused == false)
{
   PlayerMovement.MovementEnabled = false;
   gameIsPaused = true;
   Time.timeScale = 0f;
   StartCoroutine(CheckIfGameCanBeUnPaused());
   print("The game is paused");
   OpenPauseMenu();
}
private void OpenPauseMenu()
{
    PauseMenuUIDocumentManager.PauseMenuContainer.style.display = DisplayStyle.Flex;
}

The issue that caused the UI not to work is that I had two UI documents that overlap in the same scene. All I had to do was to change how much screen space the other element took up.

Problem:

You are using Start to bind the UI. This will produce undefined behaviours (errors and bugs) either now or in the future.

Solution:

→ Use OnEnable for all the UI binding code instead.