Trying to access a class outside of file but getting Object reference error

Hello,
I’m trying create a global class that I can access and modify from outside of the script but I keep getting this error:

NullReferenceException: Object reference not set to an instance of an object
GridSystem.Start () (at Assets/Scripts/Grid/GridSystem.cs:45)

Here’s the code of the class:

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
  
    [System.Serializable]
    public class GridManager : MonoBehaviour
    {
        private static GridManager _gridManager;
        public static GridManager Instance { get { return _gridManager; } }
        void Awake()
        {
            _gridManager = this;
        }
  
        public GridSlot[] allGrids = new GridSlot[10100];
  
        public void AddGridSlot(int id, Vector3 pos)
        {
            allGrids[id]            = new GridSlot();
            allGrids[id].id         = id;
            allGrids[id].position   = pos;
            allGrids[id].leftSlot   = id - 1;
            allGrids[id].rightSlot  = id + 1;
            allGrids[id].aboveSlot  = id + 100;
            allGrids[id].leftSlot   = id - 100;
            allGrids[id].beingUsed  = false;
        }
    }

And here’s the code where I’m trying to use the class instance outside of the file:
GridManager.Instance.AddGridSlot(i, new Vector3(curX, max.y, curZ));
Thanks for the help

Assuming GridManager.Instance.AddGridSlot(i, new Vector3(curX, max.y, curZ)); is line 45 of GridSystem.cs then it stands to reason you simply don’t have a GridManager in your scene.

I don’t know why I thought I didn’t have to actually add it to the scene. That fixed it.

Thanks