NullReferenceException: can someone help?

Hello everyone! I can’t seem to figure out what’s wrong with my script. I know what the error means, not my first encounter with it. If anyone could spot an obvious error or something, that would help a lot. Thanks in advance.

static var MTopArray : Material[];
static var MBottomArray : Material[];
static var MHairArray : Material[];
static var MShoeArray : Material[];
var MTops : Material[];
var MBottoms : Material[];
var MHairdos : Material[];
var MShoes : Material[];

var playername : String = PlayerPrefs.GetString("Player Name");
var topInt : int = PlayerPrefs.GetInt("Top");
var bottomInt : int = PlayerPrefs.GetInt("Bottom");
var hairInt : int = PlayerPrefs.GetInt("Hair");
var shoeInt : int = PlayerPrefs.GetInt("Shoe");
var gender : int = PlayerPrefs.GetInt("Gender");

static var FTopArray : Material[];
static var FBottomArray : Material[];
static var FHairArray : Material[];
static var FShoeArray : Material[];
var FTops : Material[];
var FBottoms : Material[];
var FHairdos : Material[];
var FShoes : Material[];

var maleRenderer : Renderer;
var femaleRenderer : Renderer;

private var clothArray : Material[];
private var Top : Material;
private var Bottom : Material;
private var Hair : Material;
private var Shoe : Material;

function Update () {
if (CharEdGUIScript.gender == 0){
maleRenderer.enabled = false;
femaleRenderer.enabled = true;
}else{
maleRenderer.enabled = true;
femaleRenderer.enabled = false;
}


//errors point to these lines:

Top = MTopArray[topInt];
Bottom = MBottomArray[bottomInt];
Hair = MHairArray[hairInt];
Shoe = MShoeArray[shoeInt];
maleRenderer.materials = [Top, Bottom, Hair, Shoe];

Top = FTopArray[topInt];
Bottom = FBottomArray[bottomInt];
Hair = FHairArray[hairInt];
Shoe = FShoeArray[shoeInt];
femaleRenderer.materials = [Top, Bottom, Hair, Shoe];
}

[/quote]

the error makes sense.
you try to access slots on an array which was never initiated unless you filled it in the editor with valid objects.

Well, that’s not the problem. I filled out all the arrays with at least 3 different materials, and it still gives my the error. Oh well. Thanks for the reply :slight_smile:

did you check what values the topInt etc are getting?

also, which line explicitely is beeing pointed out? each of them on their own if you remove the line above?

yes, they’re all set to 0.

Yep. I appreciate you helping, by the way :slight_smile:

Nevermind, finally figured out what was wrong: never set the static arrays. :sweat_smile: thanks for lending your time anyway dreamora :slight_smile: