NullReferenceException when accessing TextAsset from array

Hey,

I’m experiencing a NullReferenceException whenever I try to access a TextAsset from an array that I’ve defined in the Unity Editor.

var partyfiles : TextAsset[];
var party = new Array();

function Awake() {
instance = this;
DontDestroyOnLoad(gameObject);
}

function Start() {
InitializeHeroes();
}

//Function to load party from text files
function InitializeHeroes(){
	var charReader : CharacterReader;
	party = new Hero[partyfiles.length];
	for(var i=0; i<partyfiles.length; i++){
		party.push(charReader.BuildCharacter(partyfiles*));*
  • }*
    }
    In the editor, I’ve attached the script to an empty game object and set the array to length 2 with text assets in each member of the array, but the game then stops and says that a NullReferenceException has occurred. Any thoughts on why this would be and how I’d go about amending it?

Your doing multi-array operations on the same line, suggest separating the operation in order to find out which array is the problem.

In the above code:
var charReader : CharacterReader; → .Buildcharacter if blank will cause the exception

partyfiles.length , if 0, will create a party of length 1, for loop & will quit on 0th iteration, i.e for(var i=0; i