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
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
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.