- Home /
NullReferenceException Error
So this is the deal. I have no error in the editor and everything is running smoothly. However when i run my build a script doesn't work. I checked the output log and i saw this message:
NullReferenceException: Object reference not set to an instance of an object at Matrix_Node_Row.updateCurveData (UnityEngine.AnimationCurve curveData) [0x00000] in :0
at Matrix_Node_Row.Update () [0x00000] in :0
(Filename: Line: -1)
So i went to the Matrix_Node_Row Class and checked the updateCurveData function. Here it is:
public void updateCurveData(AnimationCurve curveData){
if (curveData==null)
{
Debug.Log ("object "+this.ToString()+"is trying to run a null curveData");
}
if (this.curveData!=null || animateEnabled==true)
{
for (int i=0; i<row.Length; i++) {
row[i].inputCurveData (curveData.Evaluate ((i*step)+p_offset));
}
}
}
public void updateCurveData(float curveData)
{
if (curveData==null)
{
Debug.Log ("object "+this.ToString()+"is trying to run a null curveData");
}
if (this.curveData!=null || animateEnabled==true)
{
for (int i=0; i<row.Length; i++) {
row[i].inputCurveData (curveData);
}
}
}
The Update function looks like this:
if (animateEnabled)
{
updateCurveData (curveData);
//updateColorData (colorData);
}
The debug meassage is not written to the log so curveData can't be null. I don't understand where something like this can stem from and i need to present my work tommorow!!
Have a read of my explanation of null reference errors in this answer. The curveData passed to the method can never be null, because it is not a reference type.
Ok, so curveData could point to a null reference, but how could there be null a refence if this script ran completely fine in editor? This error only comes up after i build my project.
curveData is not the cause of this error, because you check if it is null. If it were null, you'd get the printout.
Something else is causing the error, and my explanation in the link I gave you in the above comment will tell you where to look.
You are testing curveData (the local variable co$$anonymous$$g from the function call, and then you test this.curveData, but you use curveData. They are not the same variable ! $$anonymous$$aybe your problem is from this misunderstanding...
Terrible Question Title Award Winner of the day
Edit : Why? Everyone who asks a question here wants help. How is this more important? Overuse of punctuation. There is an abundance of question titles already using NullReferenceException.
to Jamora for a great link
Answer by Yarden-Raveh · Feb 23, 2014 at 06:41 PM
Thanks to everyone who replied, i have found the answer. I had to initialize objects prior to the start of the scene in order to keep the scene optimized. I placed these operation in OnValidate since i also wanted to make sure they were of a specific type. However i forgot to copy the initialization operation to the Awake function. So the array row was intialized in editor but not in build.