- Home /
ApplyModifiedProperties() for UnityEvent ignores method name
Ok, so i have set up a Editor Window that has a Serialized Property for a UnityEvent, and i want to do multi objects editing, so what i do is, for the first selected object, if it has any changes in its property, simply clone the object into all the other selected objects. Kind of simple, it has worked for other objects, now when i'm dealing with a Unity Event, it doesnt seems to detect the method name as a "modification" to the object, even though it serializes correctly.
This is the part of the code that manages the thing:
string oldS = JsonUtility.ToJson(rhythm.layers[selectedLayer].markups[selectedMarkup].evt);
SerializedObject so = new SerializedObject(rhythm);
SerializedProperty sp = so.FindProperty("layers").GetArrayElementAtIndex(selectedLayer).FindPropertyRelative("markups").GetArrayElementAtIndex(selectedMarkup).FindPropertyRelative("evt");
EditorGUILayout.PropertyField(sp);
if (so.hasModifiedProperties) {
so.ApplyModifiedProperties();
Debug.Log("Old: \n" + oldS);
Debug.Log("New: \n" + JsonUtility.ToJson(rhythm.layers[selectedLayer].markups[selectedMarkup].evt));
foreach (int im in selectedMarkups) {
rhythm.layers[selectedLayer].markups[im].evt = rhythm.layers[selectedLayer].markups[selectedMarkup].evt.Clone();
}
}
When changing the object reference of the UnityEvent field, or the listener count (adding or removing), all seems to work perfectly, but when i change the method name, nothing is printed, meaning the so.hasModifiedProperties
returns false.
I have also made a little change in that code, using instead GUI.changed
, and it does get called when i modify the method name, but it doesnt actually updates the original object using so.ApplyModifiedProperties
As you can see it prints the same serialized object in the Old, and New, and neither of them is the correct one (see the "m_MethodName":"RhythmEvent", wich was supposed to be the current event name in the editor, "playOnAwake", or something like that)
It alwas show the last modification i had, so if after this i changed the method name again, it would print this time, the "playOnAwake" method