Search Issue Tracker
By Design
Votes
0
Found in
2019.3.0a2
2019.3.0a8
Issue ID
1168733
Regression
No
Unassigned private array field is not null when entering play mode with Reload Domain & Scene disabled.
How to reproduce:
1. Open the attached project ("case_1168733-PlayModeTest.zip")
2. Open the repro scene ("SampleScene")
3. Enter Play mode
4. Notice "Start: testVector is null" message in the console
5. Do a trivial change in the "PlayModeTest.cs" script and save it
6. Enter Play mode again
7. Inspect the console
Expected results: "Start: testVector is null"
Actual results: "Start: testVector is not null"
Reproducible with: 2019.3.0a2, 2019.3.0a9
Couldn't test with version 2019.3.0a1 and below because it does not have "Fast Enter Playmode" functionality.
Note:
This issue only reproduces when entering the play mode first time after the Editor recompiles the scripts
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
- Prefab override popup is cropped/positioned incorrectly when more than one display is used and a higher display Scale is set
- Opening a dropdown on a small screen results in its instant closing when mouse cursor is pressed where the dropdown is going to be opened
- Only "ArgumentNullException: Value cannot be null" is displayed instead of all the actual errors when opening a project with numerous compilation errors
- MultiColumnListView and MultiColumnTreeView do not change selection on first input when focus is set by code
- SerializedProperty.DataEquals is returning false when SerializedProperty.EqualContents return true
Resolution Note (2020.1.X):
TL;DR: This is by design. Initialize private fields on MonoBehaviours/ScriptableObjects to avoid unexpected behavior.
The serialization system in Unity does not support null and always initializes members by calling the default constructor. During domain reload we also deserialize private fields on MonoBehaviours/ScriptabbleObjects to make edit-and-continue in play mode easier to work with.
So what happens in this case is that we during domain reload create a empty array and this is stored in memory as the value for the field. Due to legacy quirks we also deserialize the MonoBehaviour during scene reload, but this time without deserializing private fields, so the value remains null.
This is why you see this issue after recompile/domain reload, where we initialize the field during domain to an empty array. And if you enter play mode without scene reload, then the field remains a empty array.