I have ScriptableObject subclass assets that I want to edit in the inspector as usual, but I don’t want my changes to the properties to be applied to the asset until I click an “Apply” button, much like how texture import settings are changed. I want this mainly because when the asset changes there’s some processes that need to happen afterwards that can take a second or two, I don’t want to call this process everytime a property is changed.
I thought that if I was to declare the serialsed properties outside the OnInspectorGUI scope that their values would stay persistent between frames, and I could then call serialsedObject.ApplyModifiedProperties after clicking the “Apply” button. Unfortunetly that hasn’t been working as the properties need to be applied the same frame I think, or their values are reverted back.
[CustomEditor(typeof(NounDefinition))]
public class NounDefinitionInspector : Editor
{
private static SerializedProperty m_NounDataProperty;
private static SerializedProperty m_NameProperty;
public override void OnInspectorGUI()
{
EditorGUILayout.PropertyField(m_NameProperty);
if (GUILayout.Button("Apply"))
ApplyChanges();
}
private void ApplyChanges()
{
if (serializedObject.hasModifiedProperties)
serializedObject.ApplyModifiedPropertiesWithoutUndo();
}
private void OnEnable()
{
m_NounDataProperty = serializedObject.FindProperty("m_NounData");
m_NameProperty = m_NounDataProperty.FindPropertyRelative("m_Name");
}
}
Would anyone have any idea of how to achieve the result I’m looking for?
I’ve looked in TextureInspector.cs source code in the UnityCsReference but I can’t find anything to do with applying the properties afterwards.
Thank you for any help!