Null Reference Exception while trying to access Text Files

I’m trying to load a piece of text from the assets folder of my project but I keep getting a Null Reference. I’ve been messing with it for a good few days trying to figure out why I’m not getting anything but I’m out of ideas. If anyone has any ideas on what I could change to make it work, they would be much appreciated. Thanks.

The problem area is on these lines here, map is set to be “Test Peon Controller” which is the name of the text file.

TextAsset mapData = Resources.Load(map) as TextAsset;
			string text = mapData.text;

The map file needs to be in the Resources folder. You’ll need to create the Resources folder if it doesn’t already exist, and place the map file inside. The filepath in the project should look like:

“Assets/Resources/Test Peon Controller”

If Test Peon Controller has a file extension (.txt) then that also needs to be included in the map string,

string map = "Test Peon Controller.txt";

Be aware of Unity’s Special Folders. Specifically Resources, in this case.

Manual - Special Folders