Ok, i have a sort-of advanced problem, which i’m sure has a simple solution, but i just can’t manage to find it…
Let’s say i have a public class, designed to be editable from the inspector…
[System.Serializable]
public class PersonType {
string gender;
bool schoolEmployee;
GameObject model;
}
…and i use this class in another class, which i assign to a gameobject, where i set several instances of it (everything filled in inspector)…
public class PeopleTypes : MonoBehaviour {
public PersonData maleStudent;
public PersonData femaleStudent;
public PersonData Teacher;
public PersonData Janitor;
}
…and i use the PersonType class as a part of another class (Person type defining the type of a person, Individual defining the individual parameters)…
public class Individual : MonoBehaviour {
string name;
int age;
PersonType pType;
}
…why do i get a nullreference exception when i try to set…
Individual ind_1 = new Individual();
ind_1.pType = PeopleTypes.maleStudent; //<- this is where i get the error
…or better yet, what would be the correct way of setting this? I guess a part of the problem would be whether this is the correct way to set up a public class for inspector editing…