i am trying to create a custom property drawer that lets me open and edit properties of a scriptable object however i want it to be done so that if i create a new scriptable object this way (only in memory and not on disk) then it should create a new instance of it.
[CustomPropertyDrawer(typeof(CharacterData))]
public class CharacterDataPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
if (GUI.Button(position, "Edit Properties"))
{
if (property.objectReferenceValue == null)
{
property.objectReferenceValue = ScriptableObject.CreateInstance<CharacterData>();
if (property.objectReferenceValue == null)
Debug.Log("this is still null");
}
EditorUtility.OpenPropertyEditor(property.objectReferenceValue);
//EditorUtility.OpenPropertyEditor(ScriptableObject.CreateInstance<CharacterData>());//This works but does not get saved obviously
}
EditorGUI.EndProperty();
}
}
I was expeting taht i would be able to create a new instace of this criptable object and edit it but i always get the debe that this is still null.
i tried using apply serializedObject.ApplyModifiedProperties(); but that did not work out either