diff --git a/Source/Editor/CustomEditors/Editors/ArrayEditor.cs b/Source/Editor/CustomEditors/Editors/ArrayEditor.cs index 335fd64a7..41ca6ba86 100644 --- a/Source/Editor/CustomEditors/Editors/ArrayEditor.cs +++ b/Source/Editor/CustomEditors/Editors/ArrayEditor.cs @@ -43,10 +43,18 @@ namespace FlaxEditor.CustomEditors.Editors // Copy old values Array.Copy(array, 0, newValues, 0, sharedCount); - // Fill new entries with the last value - for (int i = oldSize; i < newSize; i++) + if (elementType.IsValueType) { - Array.Copy(array, oldSize - 1, newValues, i, 1); + // Fill new entries with the last value + for (int i = oldSize; i < newSize; i++) + Array.Copy(array, oldSize - 1, newValues, i, 1); + } + else + { + // Initialize new entries with default values + var defaultValue = TypeUtils.GetDefaultValue(new ScriptType(elementType)); + for (int i = oldSize; i < newSize; i++) + newValues.SetValue(defaultValue, i); } } else if (newSize > 0) @@ -54,9 +62,7 @@ namespace FlaxEditor.CustomEditors.Editors // Initialize new entries with default values var defaultValue = TypeUtils.GetDefaultValue(new ScriptType(elementType)); for (int i = 0; i < newSize; i++) - { newValues.SetValue(defaultValue, i); - } } SetValue(newValues); diff --git a/Source/Editor/CustomEditors/Editors/ListEditor.cs b/Source/Editor/CustomEditors/Editors/ListEditor.cs index 19ed9675b..07963a33f 100644 --- a/Source/Editor/CustomEditors/Editors/ListEditor.cs +++ b/Source/Editor/CustomEditors/Editors/ListEditor.cs @@ -40,30 +40,35 @@ namespace FlaxEditor.CustomEditors.Editors // Allocate new list var listType = Values.Type; var newValues = (IList)listType.CreateInstance(); + var elementType = ElementType; var sharedCount = Mathf.Min(oldSize, newSize); if (list != null && sharedCount > 0) { // Copy old values for (int i = 0; i < sharedCount; i++) - { newValues.Add(list[i]); - } - // Fill new entries with the last value - for (int i = oldSize; i < newSize; i++) + if (elementType.IsValueType) { - newValues.Add(list[oldSize - 1]); + // Fill new entries with the last value + for (int i = oldSize; i < newSize; i++) + newValues.Add(list[oldSize - 1]); + } + else + { + // Initialize new entries with default values + var defaultValue = Scripting.TypeUtils.GetDefaultValue(elementType); + for (int i = oldSize; i < newSize; i++) + newValues.Add(defaultValue); } } else if (newSize > 0) { // Fill new entries with default value - var defaultValue = Scripting.TypeUtils.GetDefaultValue(ElementType); + var defaultValue = Scripting.TypeUtils.GetDefaultValue(elementType); for (int i = oldSize; i < newSize; i++) - { newValues.Add(defaultValue); - } } SetValue(newValues);