Fix duplicating array values in Editor

#1959
This commit is contained in:
Wojtek Figat
2024-03-04 18:25:57 +01:00
parent 5fdf1789ce
commit bbe08be462
3 changed files with 21 additions and 17 deletions

View File

@@ -747,7 +747,7 @@ namespace FlaxEditor.CustomEditors
/// </summary>
public void SetValueToDefault()
{
SetValueCloned(Values.DefaultValue);
SetValue(Utilities.Utils.CloneValue(Values.DefaultValue));
}
/// <summary>
@@ -784,19 +784,7 @@ namespace FlaxEditor.CustomEditors
return;
}
SetValueCloned(Values.ReferenceValue);
}
private void SetValueCloned(object value)
{
// For objects (eg. arrays) we need to clone them to prevent editing default/reference value within editor
if (value != null && !value.GetType().IsValueType)
{
var json = JsonSerializer.Serialize(value);
value = JsonSerializer.Deserialize(json, value.GetType());
}
SetValue(value);
SetValue(Utilities.Utils.CloneValue(Values.ReferenceValue));
}
/// <summary>