I am trying to display a string from a csv file as a text mesh pro text. However, I get NullReferenceException.
I checked and I've draged a text mesh pro texts into the into the appropriate places in the inspector.
public TMP_Text NameText;
string[] files = Directory.GetDirectories(path);
foreach (string file in files)
{
string[] csvLines = File.ReadAllLines($@"{file}\info.csv");
foreach (string line in csvLines)
{
CInfo CI = new CInfo(line);
NameText.text = $"loaded {CI.name}";
}
}
if I try Debug.log(CI.Name);
, it works just fine.
I have another public text mesh pro text just one line above the NameText and it works perfectly fine. The NameText on the other hand, gives a null reference exception.
public TMP_Text LocationText; //this one works
public TMP_Text NameText; // this one gives a NullReferenceException: Object reference not set to an instance of an object
They are both set to a text mesh pro text in the inspector so there shouldn't be any reason for just the NameText to give a null exception error.
NameText.text = "something"
aslo gives a null reference exception