Search Issue Tracker
By Design
Votes
0
Found in
4.6.0b9
Issue ID
611272
Regression
No
Resizing a MyClass[] array in the inspector does not make the new element have the class default values, but 0 instead
To reproduce:
1. Open the attached project. It contains a script with a serializable class that has 3 fields (bool int and float). All of them have some kind of default value. The script also creates two arrays of the class (one that is initialized with new, and one that is not initialized)
2. Attach the script to the main camera
3. Notice that the initialized arrays fields have the default values. If you increase the size of the initialized array the new elements also have the default values.
4. The uninitialized data array is by default size 0; Change the size to 1 - note that the fields do not have the default values
EXPLANATION:
Internally, when an array is resized, the core allocates a zero-initialized memory block big enough to contain the array elements. For performance reasons, this block of data is left uninitialized unless the original size was different than zero: in this case the last element's data is copied onto the newly created elements without invoking any constructor.
The behaviour for non-array fields is different, as long as the constructor gets invoked when they are initialized the first time, and by invoking the constructor the fields get initialized to their default values.
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
Add comment