cs0120 object reference not set to an instance of an object

I have been looking around for a way to fix it but I dont really understand what is wrong with my code. I have a class for units in a RTS and another class that contains the information about units (I set all the parameters to 0 in an awake()and in the update() the parameters are set accordingly to the unitClass with a switch.

    public characterParameters stats = new characterParameters();
	public int unitClass;
	public float moveSpeedNow;
            void Start ()
	{	
			stats.unitClass = unitClass;
	}

Later on I’ve got the following:

 if (destinationDistance < .5f) {
         moveSpeedNow = 0;} 
 else if (destinationDistance > .5f) {
         moveSpeedNow = stats.speed;}

The errors are at stats.unitClass = unitClass and moveSpeedNow = stats.speed .

As a bit of a guess, you probably did not initially have the ‘= new CharacterParameters()’ in your code when you added the script to your game object. Initializations of public variables only happens the first time a script is attached to an object. After that, you can only change the initial value in the Inspector.

You can solve this problem by making ‘stats’ private:

private characterParameters stats = new characterParameters();

The other way to solve it (assuming you needed it to be public for some reason) would be to initialize it in Start() instead.