I have an editor script that changes properties of an UI Element. Before the changes take place I collect all UI Scripts and RectTransforms in children and add them to Undo.RecordObjects.
Unfortunately this doesn’t work for all UI elements as they interfere with each other. For example: if I undo changes to a slider the handle moves to the middle (I guess the slider component changes the position). I think the problem is that the ordering of the undos is not well-defined but I can’t find any documentation on that.
Do you have any ideas?
Here’s the code:
`if (EditorGUI.EndChangeCheck())
{
List<Object> toRecord = new List<Object>();
foreach (Image toAdd in myScript.GetComponentsInChildren<Image>()) toRecord.Add(toAdd);
foreach (Text toAdd in myScript.GetComponentsInChildren<Text>()) toRecord.Add(toAdd);
foreach (TMPro.TextMeshProUGUI toAdd in myScript.GetComponentsInChildren<TMPro.TextMeshProUGUI>()) toRecord.Add(toAdd);
foreach (InputField toAdd in myScript.GetComponentsInChildren<InputField>()) toRecord.Add(toAdd);
foreach (TMPro.TMP_InputField toAdd in myScript.GetComponentsInChildren<TMPro.TMP_InputField>()) toRecord.Add(toAdd);
foreach (Slider toAdd in myScript.GetComponentsInChildren<Slider>()) toRecord.Add(toAdd);
foreach (RectTransform toAdd in myScript.GetComponentsInChildren<RectTransform>()) toRecord.Add(toAdd);
Undo.RecordObjects(toRecord.ToArray(), "Apply Style");
myScript.selectedElementIndex = saveSelection;
UniStyle.ActiveStyle.ApplyStyle(myScript);
}`