In this video, @sampattuzzi mentions that this bug only seems to affect “sub assets”, however I think that this might not be completely accurate.
For the last few hours I have battled with the ScriptableObject saving system, and from what I can tell, even at the top level (selectedDialogue
in DialogueEditor.cs
) the only way to get your changes onto disk is to do at least one Undo or Redo action before you attempt to save (save project or save scene, either seems to work). If you create a brand new Dialogue asset and never Undo or Redo when editing it, nothing I do seems to get it written to disk. But then one Undo, save, and bam… saved to disk. To save another change, you need to do another preceding Undo operation. Even moving a Node and undo-ing it is sufficient.
Adding this EditorUtilities.SetDirty(object)
just after all Undo.RecordObject()
calls seems to be the only way I can ensure that changes end up on disk without at least one undo. So adding this throughout DialogueEditor.cs
seems to be the way to go. A wrapper function that calls Undo.RecordObject()
and EditorUtilities.SetDirty(object)
is probably the best option at this point, assuming that Unity doesn’t pre-emptively interrupt Editor code (it might? Who knows…)
I am using watch -n1 -d=permanent "cat 'New Dialogue.asset'"
to see exactly when changes go to disk.
I’ve reproduced this with the course github repository.
I’m wondering if this might be related to no “starting position” being saved by the Undo system - do we need to somehow create a baseline Undo record in Dialogue.cs
's Awake()
function so that Undo.RecordObject()
has something to diff against? Perhaps until you attempt to actually undo or redo the dirty flag isn’t properly set by Undo.RecordObject()
? Pure speculation at this point… I played with Undo.RegisterCompleteObjectUndo()
in Dialogue.Awake()
to try and create a baseline but I wasn’t successful, yet.
EDIT: observation - if I edit the SO data via the Inspector it will save to disk immediately on a Save command, no Undo required, which is what I’d expect to see there.