It’s taken me a full day to track this bug down so I thought I’d post about it. it’s quite a bad one. What hapened was that my game suddenly started crashing when I changed any value in the inspector. Worked fine up till yesterday then suddenly it went bad. After much head scratching I eventually found out it was because I’d made an array of objects public (so I could access them from another class). Basically I create a list of rooms when the game starts up in the list rooms. If I make that list public then it shows up as a list of null variables. If I change ANY variable in the inspector the list becomes corrupt and the game frequently crashes. Making the list NonSerializable solves the problem. Why would this be?
public class Room:UnityEngine.Object
{
}
//causes problems
public List rooms = new List();
//works fine
[System.NonSerialized]
public List rooms = new List();
As an aside why does any object which is derived from UnityEngine.Object return false when compared to null? E.g. the following always returns true:
Room room = null;
if(room != null)
Debug.Log(“Always runs this line”)
this on the other hand works as expected:
Room room = null;
if((object)room != null)
Debug.Log(“Never runs this line”)
I’m guessing it’s because the unityengine.object overloads teh equivalence operator but what for?
regards,
tony