I have the database that is basically a scriptable object (CellsDatabase):
[System.Serializable]
public class CellClassModification
{
public Type name;
public int price;
}
[System.Serializable]
public class CellClassData
{
public Type name;
public GameObject prefab;
public List<CellClassModification> modifications;
public CellClassData()
{
name = null;
prefab = null;
modifications = new List<CellClassModification>();
}
public CellClassData(Type type)
{
name = type;
prefab = null;
modifications = new List<CellClassModification>();
}
}
[System.Serializable]
public class CellsDatabase : ScriptableObject
{
public List<CellClassData> cells;
public CellsDatabase()
{
cells = new List<CellClassData>();
SyncClasses();
}
. . .
}
And the editor window for this database
Each class has a list of upgrades (CellClassModification) that instance of this class can transform into, paying the price.
Every time you open editor window it loads data from the same scriptable object.
And it works good. But after Unity recompiles scripts or Unity restarts I’m getting null reference exceptions here:
activeCellClass.modifications[a].**name**.Equals(...)
where:
- modification is an instance of CellClassModification,
- modifications[a].name == null (But it shouldn’t)
I don’t understand how does modification.name get null value. Maybe some serialization issues?