Hey guys n gals.
I just found a rather curious problem with Unity 3.4. As it is, I am not a big fan of MonoDevelop. Unitron just feels so much more… right! I can’t explain it. Anyways, I use Unittron for everything and just switch to MonoD if I run into a bug I can’t track down.
So yeah, here I am, coding away in Unitron, my code compiles cleanly and yet at runtime my code throws an “Object reference not set to an instance of an object” error. Granted, it is in Update so perhaps this class of mine has not yet been instantiated… even though I do call it in Start… So I change my coding. Instead of referencing the variable, I now say: If (myvar) Debug.Log(myvar.curVal = “”); … and the Debig.Log still throws out the same error!!! What the hell??? How can Debug.Log() printing a normal int cause this error??? And then I noticed it…
This code of mine actually compiled cleanly! Look carefully at the variable in use. I make reference to a variable that doesn’t exist, but the compiler doesn’t issue any errors until runtime… Perhaps because the var I use is spelled the same as the one that DOES exist up to where the name ends??? I dunno. But for some reason using curVal compiles clean even though the variable is called curValue…
Go figure…
//myfile.js
class myClass extends Object
{
var curValue : int = 50;
}
var myVar : myClass;
function Start()
{
myVar = new myClass();
}
function Update()
{
Debug.Log(myVar.curVal); <----- LOOK AT THIS!!!
}
Edit: Just tried something else.
class crCountDownTimer extends Object
{
var val : int;
}
class crTimedStat extends Object
{
var curValue : int;
var timer : crCountDownTimer;
}
var FatigueTimer : crTimedStat;
function FatigueUpdate(amount)
{
if (FatigueTimer != null)
{
Debug.Log(FatigueTimer.curVal + "<----");
FatigueTimer.timer.value = 60; <-- THIS COMPILES CLEANLY
}
}


