I tried to make a simple class to store data during runtime. I did not want to attach it to a GameObject because it will be deleted almost right after it was made. I made it to convert into a JSON string and get sent to client-side javascript.
Data Class:
public class ExampleData {
public string[] target;
public string sender;
public string type;
}
The problem - I was trying to test out the JSON string conversion but the class is not registering. Because it does not extend Monobehaviour, I tried to treat it like a class in regular programming by using the keyword βnewβ. This is where the error is:
void TestData() {
ExampleData exData = new ExampleData();
exData.target[0] = "all"; //exData is not set to an instance?? Should be
exData.sender = "a_name";
exData.type = "test";
string updateData = JsonUtility.ToJson(exData);
Debug.Log(updateData);
}
Everything is picked up by Visual Studio fine. With no errors, but Unity says this message:
NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)
Any advice would be greatly appreciated. Thank you.