Search Issue Tracker
Duplicate
Votes
1
Found in
5.2.3f1
Issue ID
748304
Regression
No
Default integer values is 0 in arrays of serializable classes even if in the script is set otherwise
To reproduce:
1. Open attached project
2. Open "Main" scene
3. Select "SerializedDefaultsTest" game object in the Hierarchy
4. In the Inspector set "Foos" array size to 1
5. Notice that "Bar" value is 0
6. Open "SerializedDefaultsTest.cs" script
7. Notice that default "Bar" value in script is set to 1, not 0
Expected behavior: "Bar" value should be 1
Actual behavior: "Bar" value is 0
Comments (1)
-
Sycobob
Feb 21, 2016 01:59
This applies to *all* serialized fields of any type. When in an array, field initializers and values set in the constructor are ignored and all fields are set to default values for their types. Contrast this with serialized fields in objects that are no in collections where field initializers and constructors are respected. This destroy the ability to provide coherent default values to designers for objects that will be used in collections.
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
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
This is a duplicate of issue #768959