- Home /
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?
Answer by Mattivc · Jun 15, 2012 at 11:17 AM
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.
Have you tried moving this conditional code to the end of your class? I'm not sure if this has an impact on the order the variable get serialized, but it might work ;)
I'm really confused since the serializer is usually smart enough to adapt the serialized data according to the field name...
Your answer

Follow this Question
Related Questions
error using IL2CPP on build 1 Answer
Json . NET, iOS and AOT 1 Answer
Serialize on iOS , that is AOT safe. 2 Answers