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
- Crash on RaiseException when opening a specific project
- DownloadHandlerScript.CompleteContent is called twice when building for WebGL
- Scene view has Y coordinates of the Screen Position node flipped when some of the URP features are disabled
- Volumetric fog shader variants are missing from build when "Strict Shader Variant Matching" is disabled
- Unnecessary modifications clutter the Scene when using a RectTransform driven by a LayoutGroup in a Prefab
Add comment