Search Issue Tracker

By Design

Votes

1

Found in

5.3.4f1

Issue ID

789372

Regression

No

NullReferenceException when selecting game object and the game manager object in the hierarchy is not selected

Serialization

-

How to reproduce:
1. Open the attached project "789372Exception.zip"
2. Open and play Example scene
3. Click 3 times on the left object in the game view
4. Notice NullReferenceException
5. Select Game Manager in Hierarchy and repeat steps 2-3
6. There is no exception

The GameManager component has a serializable field. When the GameManager is created at runtime, this field is null. However, if the GameManager GameObject is selected in the editor, the field that was null become instantiated and is no longer null.

Thus, simply selecting GameObjects in the editor can change how the game executes. This is an issue in how we handle serialization.

  1. Resolution Note (2017.2.0f3):

    The behavior seen is a consequence of the serialization layer's design decisions: 'ref values' (classes) are treated as 'value types' and the scenario here is that object state differs between if a serialization/deserialization cycles occurred vs if it did not occur, basically: user is assuming that serialization restores objects exactly as it was, which is not true for 'ref types'.

    of note: is an up coming version, unity will have support for serializing ref types as references in an 'opt-in' manor, so would not fix this issue out of the box, but would give the user one more path forward.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.