I keep getting the UnassignedReferenceException and I don't know how to fix it

I’m trying to make it so that the users can select how many players they want to play with, what level they want to play, and choose their settings all in the same screen. So far, whenever I try to enter the settings I keep getting the unassigned reference exception. This doesn’t happen anywhere else and everything seems to be fine. Is there something wrong I’m doing? Here is the code by the way:

using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainManager : MonoBehaviour
{

    public int playerCount; // Determines the amount of players that are playing in the current game
    public int levelsBeaten; // Counts the amount of levels the players have beaten already
    public int currLevel; // Determines the current level
    public static MainManager Instance; // Will get the instance of the main manager script or object or something??

    public GameObject playerSelectCanvas; // The canvas where the amount of players are selected
    public GameObject levelSelectCanvas; // The canvas where the level is selected
    public GameObject settingsCanvas; // The canvas where the settings are located
    public GameObject BG1; // Background 1
    public GameObject SettingsBG; // Background 2

    public void Awake()
    {
        playerSelectCanvas = GameObject.FindGameObjectWithTag("Player Select");
        levelSelectCanvas = GameObject.FindGameObjectWithTag("Level Select");
        settingsCanvas = GameObject.FindGameObjectWithTag("Settings Select");
        BG1 = GameObject.FindGameObjectWithTag("Background 1");
        SettingsBG = GameObject.FindGameObjectWithTag("Settings Background");

        if (SceneManager.GetActiveScene().name == "Home Screen") {
            playerSelectCanvas.SetActive(true);
            levelSelectCanvas.SetActive(false);
            settingsCanvas.SetActive(false);
            BG1.SetActive(true);
            SettingsBG.SetActive(false);
        }

        if (Instance != null) {
            Destroy(Instance);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);
    }


    public void PlayerSelect(int players)
    {

        playerCount = players;
        playerSelectCanvas.SetActive(false);
        levelSelectCanvas.SetActive(true);
        BG1.SetActive(false);
        SettingsBG.SetActive(true);

    }

    public void PlayerSelect()
    {

        playerSelectCanvas.SetActive(false);
        levelSelectCanvas.SetActive(true);
        BG1.SetActive(false);
        SettingsBG.SetActive(true);

    }

    public void SettingsSelect() {

        Debug.Log(settingsCanvas);
        Debug.Log(BG1);
        Debug.Log(SettingsBG);

        settingsCanvas.SetActive(true);
        BG1.SetActive(true);
        SettingsBG.SetActive(false);

    }

    public void LevelSelect(int level) {

        currLevel = level;
        SceneManager.LoadScene(1);

    }

}

The answer is always the same… ALWAYS!

How to fix a NullReferenceException error

Three steps to success:

  • Identify what is null ← any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

NullReference is the single most common error while programming. Fixing it is always the same.

Some notes on how to fix a NullReferenceException error in Unity3D:

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