[BUG] ScriptableObject do not sync when being edited by custom editor
Bl4ck-orig opened this issue · 2 comments
Bl4ck-orig commented
Describe the bug
When an asset created by a class deriving from ScriptableObject is changed by a custom editor, the changes are not synced.
To Reproduce
Steps to reproduce the behavior:
- Create new Unity Project 2020.3.36f1.
- Create File "ParalSyncEditorBug.cs" and copy code into file at the bottom.
- Create asset by right clicking in Project Window -> create/ParalSyncEditorBug.
- Create entry in the created asset for "Test Variable".
- Clone Project.
- Click Clear Data Button.
- Save File & Project.
Expected behavior
The asset is synced in both projects.
Enviroment (please complete the following information):
- Unity Editor Version: 2020.3.36f1
- ParrelSync Version: 1.5.1
- OS Version: Windows 10 21H2
Additional context
ParalSyncEditorBug.cs:
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CreateAssetMenu(fileName = "ParalSyncEditorBug", menuName = "ParalSyncEditorBug")]
public class ParalSyncEditorBug : ScriptableObject
{
[SerializeField] private List<int> testVariable;
public void ClearData() => testVariable = null;
}
[CustomEditor(typeof(ParalSyncEditorBug))]
public class ParalSyncEditorBugEditor : Editor
{
public override void OnInspectorGUI()
{
ParalSyncEditorBug test = (ParalSyncEditorBug)target;
DrawDefaultInspector();
if (GUILayout.Button("Clear Data"))
test.ClearData();
}
}
314pies commented
Hi Bl4ck-orig,
It seems you didn't mark the scriptable object as dirty after you cleared the data.
Can you try to add EditorUtility.SetDirty(test);
after the line test.ClearData();
?
The final result should be somehow like this:
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CreateAssetMenu(fileName = "ParalSyncEditorBug", menuName = "ParalSyncEditorBug")]
public class ParalSyncEditorBug : ScriptableObject
{
[SerializeField] private List<int> testVariable;
public void ClearData() => testVariable = null;
}
[CustomEditor(typeof(ParalSyncEditorBug))]
public class ParalSyncEditorBugEditor : Editor
{
public override void OnInspectorGUI()
{
ParalSyncEditorBug test = (ParalSyncEditorBug)target;
DrawDefaultInspector();
if (GUILayout.Button("Clear Data")) {
test.ClearData();
EditorUtility.SetDirty(test);
}
}
}
Bl4ck-orig commented
Hello.
Did not know about this function! My bad.
Thank you!
Cheers.