if (gameobject != null) giving UnassignedReferenceException

So I’m creating a game in which the player has several playing pieces to choose from. I’ve created a game manager which is a singleton (and I think that might be part of my problem). The pieces are Unity UI buttons, and when they are clicked a script on the Manger is called which stores which piece was clicked on. If another piece was already selected, I want to forget about the piece and as a visual cue to the player I’m adjusting the scale. So here’s my code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Manager : MonoBehaviour {

	public static Manager manager;
	GameObject chosenPiece = null;

	void Awake()
	{
		if (manager == null)
		{
			//DontDestroyOnLoad(gameObject);
			manager = this;
		} else if (this != manager)
		{
			Destroy(gameObject);
		}
	}

public void PieceClicked(GameObject thisPiece)
	{
		Vector3 scaleFactor = new Vector3(0.1F, 0, 0.1F);
		if (chosenPiece != null)
		{
			chosenPiece.transform.localScale -= scaleFactor;
		}

		thisPiece = chosenPiece;
		chosenPiece.transform.localScale += scaleFactor;
	}

Trouble is when I run it, I get this error

UnassignedReferenceException: The
variable chosenRune of Manager has not
been assigned. You probably need to
assign the chosenRune variable of the
Manager script in the inspector.

I also tried changing around my if statement so that it was if (chosePiece == null) and even tried if(chosenPiece == null || chosenPiece.Equals(null)) but I got the same errors that way.

Most people who have similar error seem to have an issue with the script being attached to multiple objects. I’ve gone through and double checked, and there is only one version of the Manager Script in the scene once I’ve hit play (before as well). So why can’t I check if my chosenPiece is null?

I think the error lies in line 30

  thisPiece = chosenPiece;

You never assign a value to chosenPiece.
In the next line you write

chosenPiece.transform.localScale += scaleFactor;

which gives you an UnassignedReferenceException because chosenPiece still has not been assigned.
If you change line 30 to

chosenPiece=thisPiece;

you should get rid of that exception.

Uhm, the error is most likely thrown on line 31, isn’t it?

We really have too much null-reference-exception questions here on UA. If you post a question about such an error post the whole complete error. You can copy and paste it from the console.

btw: this line makes no sense:

thisPiece = chosenPiece;

“thisPiece” is a parameter of your method. Why would you set it to the chosenPiece? Don’t you want to do it the other way round?

chosenPiece = thisPiece;