NullReferenceException, object not set to instance of an object. Help?

Hey guys.

I’ve been wrestling with this Null Reference Exception for too long. The script below is a spawner script that supposedly instantiates an Enemy in the game world everytime the game starts. Somehow I keep getting this error and I have no clue where I’m missing a reference to the object… The prefab is linked to the script via the editor.

This is the error message I get, in case it is useful for anyone trying to help me:
“NullReferenceException: Object reference not set to an instance of an object
Camp.Awake () (at Assets/Resources/Camp.cs:38)”

public class Camp : MonoBehaviour {

	LocalDatabaseConnector ldbc;
	Enemy enemyScript;
	public GameObject enemy;
    private List<string> enemyPool()
    {
        List<string> enemyList = new List<string>();
        switch (campDifficulty)
        {
            case 0:
                enemyList.Add("EasyBaddie");
                enemyList.Add("EasyRanger");
                return enemyList;
            
            case 1:
                enemyList.Add("MedBaddie");
                enemyList.Add("MedRanger");
                return enemyList;
            case 2:
                enemyList.Add("BigBoss");
                enemyList.Add("MedRanger");
                return enemyList;
            default:
                return null;

        }
    }
    public int campDifficulty;


	// Use this for initialization
	void Awake () {
		enemyScript = enemy.GetComponent<Enemy> ();
		StartCoroutine(ldbc.FillEnemy("Baddie", enemyScript));
		Instantiate(enemy, this.transform);
        //spawnEnemy();
	}
	
	// Update is called once per frame
	void Update () {
		
	}
    void spawnEnemy()
    {
		
        
    }
}

Thanks for the attention in advance :slight_smile:

It looks like you haven’t assigned a gameObject to enemy yet?

Go into Unity and drag the object you want to be considered as the “enemy” into the inspector panel of the script where there is this little box saying empty (gameObject)