I am trying to serialize a list of integers to save and am getting an “object reference not set to an instance of an object” error - this is for a code that I had used in Unity 2018 and am trying to use in Unity 2021.1.19. When I save individual integers, floats, etc to “unitSave” in the code below, there are no problems - it’s only when I try to add them to a list.
public class ObjectSaveStats
{
public List<float> playerUnits;
public string unitName;
}
public void Save()
{
List<ObjectSaveStats> saveList = new List<ObjectSaveStats>();
for (int i = 0; i < allUnitsList.Count; i++)
{
unitSave.unitName = allUnitsList*.GetComponent().unitName; THIS WORKS
unitSave.playerUnits.Add(allUnitsList*.GetComponent().unitID; THIS GENERATES AN ERROR
}
}