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
- Sprite artefacts appear when Sprite Packer is enabled
- Crash on ResizeScriptingList<ScriptingObjectPtr> when passing an undeclared variable to the results parameter for GameObject.FindGameObjectsWithTag
- [Android] "Screen.safeArea.y" always returns values outside of the Safe Area when the device is in Portrait orientation
- Frame spike due to many TreeRenderer.TreeUpdated calls when repositioning terrains in large Scenes
- Crash on GameObject::RemoveComponentFromGameObjectInternal when reparenting Text GameObjects
This is a duplicate of issue #768959