object reference not set to an instance of an object

i’m just learning Unity.I’m going to ask an easy question but I couldn’t solve the problem.I am getting the following error while trying to access other Script’s function.

public class MainMenuManager : MonoBehaviour
{
    [SerializeField]
    private GameObject seviyePanel,mainMenuPanel;

    GameManager gameManager;
    string hangiIslemHangiSeviye;

    private void Awake() {
       gameManager = Object.FindObjectOfType<GameManager>();
    }

    public void BtnKolay()
    {
        if (hangiIslemHangiSeviye == "btnTopla")
        {
            gameManager.HangiSeviyeHangiIslem(); // HERE MY ERROR line 118
            SceneManager.LoadScene(1);
          
        }
}

-----------------------------------------------------------------------------

public class GameManager : MonoBehaviour
{
    [SerializeField]
    private GameObject soruPanel;

    [SerializeField]
    private Text txtSoruPanel;

    int test = 0;

    void Start()
    {
        HangiSeviyeHangiIslem();
    }

    public void HangiSeviyeHangiIslem()
    {   
            test++;      
    }
}

7972230--1022802--Screenshot 2022-03-17 195958.png

gameManager is null.

You need to use GameObject, not Object

Fortunately it’s such a common problem there a pinned post for the ONLY three steps that will ever fix it.

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Steps to success:

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

The script connected the object named “GameManageree”. Can you explain

That line is probably your issue.

Can anyone offer a solution?

Did you at least do the first step?? Until you do, you won’t solve this, I promise you.

I’ll post it again for you:

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Steps to success:

  • Identify what is null <------ start here, dedicate 100% of your focus to this problem. See the link for how
  • Identify why it is null
  • Fix that