Search Issue Tracker
By Design
Votes
0
Found in
2022.3.58f1
6000.0.40f1
6000.1.0b8
6000.2.0a5
6000.3.0a1
Issue ID
UUM-99471
Regression
No
Top-level lists are handled differently than nested lists when using JsonUtility.FromJson
How to reproduce:
1. Open the attached “IN-94949 json“ project
2. Open the “SampleScene“ and enter Play Mode
3. Observe the result in the Console Window
Expected result: The top-level list is set to null, which causes an error and prints "NullReferenceException: Object reference not set to an instance of an object" in the Console window
Actual result: The top-level list is initialized as an empty list, “0“ is printed in the Console window
Reproducible with: 2022.3.58f1, 6000.0.40f1, 6000.1.0b8, 6000.2.0a5
Reproducible on: MacOS 15.3 (M4), Windows 11 (by user)
Not reproducible on: No other environments tested
Notes:
- Top-level list in “SomeScript.cs“ component which is applied on “Test“ GameObject behaves differently from what is described in the documentation (https://docs.unity3d.com/6000.2/Documentation/ScriptReference/JsonUtility.FromJson.html): “If the JSON representation is missing any fields, they will be given their default values (i.e., a field of type T will have value default(T) - it will not be given any value specified as a field initializer, as the constructor for the object is not executed during deserialization).” The top-level list is missing from the JSON and does not have an initializer in the code, however it is not set to its default value (null). Instead, it’s automatically initialized as an empty list, allowing operations like ".Count" without throwing a "NullReferenceException"
- Top-level list {{firstLevelUninitialized}} and second-level list {{secondLevelUninitialized}} in component “SomeScripts.cs“ return different outputs in the Console Window even though both even though both have no initializer in the code
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
- var VisionOSEDRHeadromm has a comma instead of a dot when building with Metal Rendering App Mode and local OS localization is set to German
- IAP Catalog remove product “x” and add product “+” buttons are not consistent with other remove and add buttons in the Editor
- Performance issues in Play Mode when quickly hovering the mouse cursor over Hierarchy GameObjects
- Frame Debugger displays incorrect output when FidelityFX Super Resolution or Spatial-Temporal Upscaler is used with Temporal Anti-aliasing or Subpixel Morphological Anti-aliasing
- The layout system is failing to correctly calculate or apply the height of the Japanese fallback font when the primary English font's metrics are used
Resolution Note:
Thank you for reporting this behaviour to Unity.
Today we will be closing this case. Thank you again for taking the time to report this.