Null Reference Problem - Emergency - Help! (same prob/diff variables)

Hi… Having " NULL REFERENCE " Problem, even though the variable is set to ‘1’, its coming up somewhere as NULL - then in mid loading- I’m getting this error:

The main problem is now this:

I found another place the error has jumped to.

Fixed some things,but had an error in this next section (Line 99):

// GUI MATRIX
if(matrixAngle != previousAngle || matrixPosition != prevMatrixPosition) { //only calculate new Quaternion if angle changed
	quat.eulerAngles = Vector3(0.0, 0.0, matrixAngle);

(It says the cause is x 2:
swipeCtrl.maxValue = 1;
and
var offset : float = swipeCtrl.smoothValue - Mathf.Round(swipeCtrl.smoothValue);
and the second problem.
NOTE: I have multiple scripts that are copied with different title names - but same programming - just changed the titles of the files, and the name of some variables to suite the multiple copies of this script.

NullReferenceException: Object reference not set to an instance of an object
ImageDisplay4.Awake () (at Assets/Scripts/ImageDisplay4.js:63)
UnityEngine.Object:Instantiate(Object)
$:MoveNext() (at Assets/viewer-scripts/LOADCONTROL.js:265)

Here is the main chunk of code thats having the problem…

	//Set up SwipeControl
//swipeCtrl.partWidth = img.width;
swipeCtrl.maxValue = 1;
if(expandInputAreaToFullWidth) {
	swipeCtrl.SetMouseRect(new Rect(-Screen.width * 0.5, imgRect.y, Screen.width, imgRect.height)); // Use image-height for the input-Rect, but full screen-width
} else {
	 swipeCtrl.SetMouseRect(imgRect); //Use the same Rect as the images for input
}
swipeCtrl.CalculateEdgeRectsFromMouseRect(imgRect);
swipeCtrl.Setup();
/*
//Determine center position of the Dots
if(dotRelativeCenterPos == Vector2.zero) dotRelativeCenterPos.y = imgRect.height * 0.5 + 14;
dotRelativeCenterPos = new Vector2((imgRect.x + imgRect.width * 0.5) + dotRelativeCenterPos.x, (imgRect.y + imgRect.height * 0.5) + dotRelativeCenterPos.y);

*/
if(centerMatrixOnScreen) {
matrixPosition.x += Mathf.Round(Screen.width * 0.5);
matrixPosition.y += Mathf.Round(Screen.height * 0.5)+176;//this is it adddown spawn extra space down
}

}

function OnGUI () {

// GUI MATRIX
if(matrixAngle != previousAngle || matrixPosition != prevMatrixPosition) { //only calculate new Quaternion if angle changed
	quat.eulerAngles = Vector3(0.0, 0.0, matrixAngle);
	previousAngle = matrixAngle;
	matrix = Matrix4x4.TRS(matrixPosition, quat, Vector3.one);	//If you're no longer tweaking
	prevMatrixPosition = matrixPosition;
	swipeCtrl.matrix = matrix; // Tell SwipeControl to use the same Matrix we use here
}
GUI.matrix = matrix;		

// IMAGES
var offset : float = swipeCtrl.smoothValue - Mathf.Round(swipeCtrl.smoothValue);
var mainPos : float = imgRect.x - (offset * imgRect.width);
if(Mathf.Round(swipeCtrl.smoothValue) >= 0 && Mathf.Round(swipeCtrl.smoothValue) < 1) {
	GUI.color.a = 1 - Mathf.Abs(offset);
	GUI.DrawTexture(new Rect(mainPos, imgRect.y, imgRect.width, imgRect.height), img);//[Mathf.Round(swipeCtrl.smoothValue)]);

// GUI.DrawTexture(new Rect(mainPos, imgRect.y, imgRect.width, imgRect.height), img);//[Mathf.Round(swipeCtrl.smoothValue)]);

}

Thanks for the help, in advance…

Kris

F.Y.I. - I tried setting the first part (quoted above) to "0" (zero) - with NO Effect...

I appreciate that you deleted your answer. I wasn't saying you can't post your whole code, but to do it in your original question and to format it properly... at the end of your question, at the left, quite small and light gray there's a button 'edit'. If you click it, you can fix up your original post with more information. remove the old code. then paste the full new code. Select the full new code. Then hit the little 101010 button...

2 Answers

2

Are you accessing swipeCtrl anywhere above the line where you get the error and it is successful? (I guess not)

My bet is you try to reference some SwipeControl-script but this assignment fails. Now if you try to access a variable in the SwipeControl-script (that has not been referenced successfully) it gives you the nullreferenceexcept. So your problem is most likely somewhere above the code-sniplet you posted.

Greetz, Ky.

Found the Solution:

Thanks for your replies!.. I ended up creating a prefab that I could drag and drop into the Variable that had the Null (within Unity 3D).

Again, I appreciate your responses!

Cheers,
Kris

Glad you found your solution :) Please click on the little check mark to the top left of this answer to mark it as 'the answer', so that this question turns green and everyone can see from the outside that this is solved =)