NRE in my Inventory GUI

While working on my inventory GUI, I’ve got NRE that I think I shouldn’t have gotten (in seemingly random place). Here’s the code with marked place, where I got NRE:

	bool InventoryButtonWidget(int x, int y, Inventory inv, int index) {
		GUIStyle leftLabel = GUI.skin.label;
		GUIStyle rightLabel = GUI.skin.label;
		leftLabel.alignment = TextAnchor.MiddleLeft;
		leftLabel.font.material.color = nameColor; //here
		rightLabel.alignment = TextAnchor.MiddleRight;
		rightLabel.font.material.color = amountColor; //and probably here (never got so far)
		bool temp = GUI.Button(new Rect(x,y,64,64),inv.getItemIcon(index));
		GUI.Label(new Rect(x+GUI.skin.button.margin.left,y+64-24,64-GUI.skin.button.margin.left - GUI.skin.button.margin.right,24),inv.getItemName(index),leftLabel);
		int amount = inv.getItemAmount(index);
		if (amount>1) { //do not draw item amount if we just have one item
			GUI.Label(new Rect(x+GUI.skin.button.margin.left, y+GUI.skin.button.margin.top,64-GUI.skin.button.margin.left-GUI.skin.button.margin.right,24),amount.ToString(),rightLabel);
		}
		return temp;
	}

nameColor and amountColor aren’t at fault here as those are public Color variables that defaults to Color.Green and Color.Red respectively. So they aren’t null. I have no idea what I’m doing wrong, please help.

This is going to sound weird, but the Font is returning null despite the fact that a font displays. I’m puzzled by this, but to fix your NullReferenceError you just need to add the following before you start manipulating anything with the font:

rightLabel.font = Gui.skin.font;
leftLabel.font = Gui.skin.font;

Although this fixes the NRE, I can’t say whether or not there are any other errors or strange behaviors that will come up with the GUI system since I’ve never done GUIStyles through code. I’ve always just added them as a variable to the component and adjusted settings in the inspector.