Nullreference on device only

I am working on a unity iOS game and i am having a problem where i get a “NullReferenceException: A null value was found where an object instance was required.” error, but this happens only when i run the game on a iOS device.

I have a monodevelop script with a list of a custom class objects. This object has a transform variable, and its this that is casing the NullReference error. The custom class list and the transform is all set up and assigned in the inspector.

I suspect there is some sort of serialization problem here. Anyone got a suggestion for what the problem might be?

The script in question, error occurs on line 93

The guys in the IRC channel helped me find the cause.

The cause is this block of code:

#if UNITY_EDITOR
                public bool fold = true;
#endif

Since this variable is not compiled on the device the class suddenly have one less variable that the serialization data, casing it to no longer match, therefore the transform variable wasn’t initialized which again caused the NullReference.