NullReferenceException: Object reference not set to an instance of an object - MonoBehaviour

This is driving me mad as this script should work and makes sense to me, basically where the error is occurring is where I want a MonoBehaviour script to be disabled/false and the other one to be true, here is the first 26 lines of code.

#pragma strict

//Inspector variables

public var actionOnSpotted : MonoBehaviour;
public var soundOnSpotted : AudioClip;
public var actionOnLostSight : MonoBehaviour;

//Private variables

private var player : Transform;
private var enemy : Transform;
private var visualArea : boolean = true;

function Awake ()

{
	player = transform;
	enemy = GameObject.FindWithTag("Enemy").transform;
}

function OnEnable()

{
	actionOnLostSight.enabled = true;
	actionOnSpotted.enabled = false;
}

Now it is saying the error is on line 26 and saying that it’s not referencing anything, but on the Inspector there is a script attached so in theory, this code should be working fine…Or am I missing something?

Try putting the “actionOnSpotted” script on Standart Assets folder so it would compile before other scripts.If that solves your problem that means it was about the compiling order.

More detailed information can be found here : http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html

Thanks, that sorted the problem!