NullReferenceException Error

Hello, I am making game (obviously) and I keep getting the NullReferenceException: Object reference not set to an instance of an object error for my void Start function.

My code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UI : MonoBehaviour
{
    //Public variables
    public Canvas pauseMenu;
    public Canvas settings;
    public GameControls gameControls;
    //Setup
    void Start()
    {
        gameControls.Player.Pause.performed += _ => Pause();
    }

    public void Quit()
    {
        Application.Quit();
    }

    public void openSettings()
    {
        settings.enabled = true;
    }

    public void Resume()
    {
        Time.timeScale = 1f;
        pauseMenu.enabled = true;
    }

    public void Pause()
    {
        Time.timeScale = 0f;
        pauseMenu.enabled = true;
    }

    //controls.
}

Full error:
NullReferenceException: Object reference not set to an instance of an object
UI.Start () (at Assets/UI.cs:16)

gameControls variable is null at the moment when you use it.
Most likely you didn’t reference it in the inspector.

Some notes on how to fix a NullReferenceException in Unity3D (also Unassigned Reference errors):

http://plbm.com/?p=221

The basic steps outlined above are:

  • Identify what is null
  • Identify why it is null
  • Fix that.