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
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.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Point Light in "LensFlareShowroom" scene of URP Samples uses unsupported Indirect Multiplier
 - Video does not play in macOS build when built app is placed in a path with a space in it on a specific project
 - Crash on AuxWindowManager::OnGotFocus when trying to maximize a tab while Visual Effect Graph window is open
 - “NullReferenceException: Object reference not set to an instance of an object” error is thrown when
 - [Metal] Game freezes after command buffer Timeout error
 
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.