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

Serialization

-

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

  1. This is a duplicate of issue #768959

    Wrong default value for array elements added in inspector

Comments (1)

  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

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.