Riddle me this, my friends…
When running this script:
var materialArray : Material[];
var thisObject : GameObject;
private var index : int = 0;
function Awake () {
thisObject.renderer.material = materialArray[index];
}
function Update () {
if (Input.GetKeyUp("1")) {
index--;
if (index < 0) {
index = materialArray.Length - 1;
}
thisObject.renderer.material = materialArray[index];
}
if (Input.GetKeyUp("2")) {
index++;
if (index > materialArray.Length - 1) {
index = 0;
}
thisObject.renderer.material = materialArray[index];
}
}
function OnMouseOver () {
GlobalVariables.DebugMessage = "Looking at me!";
Debug.Log ("OnMouseOver");
}
function OnMouseExit () {
GlobalVariables.DebugMessage = " Not looking at me!";
Debug.Log ("OnMouseExit");
}
I get the following error:
UnassignedReferenceException: The variable thisObject of 'CheckIfFocus' has not been assigned.
You probably need to assign the thisObject variable of the CheckIfFocus script in the inspector.
CheckIfFocus.Awake () (at Assets/Scripts/CheckIfFocus.js:7)
Now here’s the funny part: that GameObject has in fact been assigned (it’s the object the script is on), and what’s more…the script works! It does everything it is supposed to do (apart from the MouseOver/Exit), but still I get the error saying it doesn’t work. Is this a bug or am I completely overlooking something?

I’ve tried renaming the variable, making a new one, I’ve even tried exporting to a Unity package and importing in a new Project, as someone suggested. Nothing works.
Can anyone help me out with this mystery?
This other question: http://answers.unity3d.com/questions/39524/getting-unassignedreferenceexception-even-though-r.html Also seems to have the same problem, supporting the theory.
– CHPedersenOh, jeez, that seems to be the case. Man, no idea how that happened, but there you go, problem solved. Thank you! Sometimes you just blind yourself, staring at your code, only to overlook the simplest of explanations.
– Story_Specialist