Has anyone been experiencing any issues with EditorUtility.SetDirty() in Unity 5.3.x? I’ve just noticed that it no longer seems to be working for me - I use it with some of my level builder code but haven’t built any new levels in a few weeks. It’s possible that it stopped in 5.3.0 and I didn’t notice it.
Just want to confirm if anyone else is having issues with it?
If it is that scenes are not marked dirty, this has been the case since 5.0, but the dirty flag is now respected when saving scenes (while in 5.0-5.2 a save would always save the scene even if it wasn’t marked as dirty).
Pretty much this. So I make a change to an object through an Editor script and mark it as dirty. Then I save the scene, load a different scene, come back to the original scene - and the changes I made weren’t saved.
Edit I did have a problem that I was asking about, but of course I had an epiphany moments after assuming it was Unity’s fault. (I noticed the asterisk showing that I had failed to save my own code file.) I left my working pseudo-code up, hoping it helps others.
I’m sorry Unity, for assuming it was your fault the SetDirty wasn’t working correctly!
It’s not working on Unity 2017.3.0f3 when I try to edit a ScriptableObject of Playmaker FSM Template. I’m using:
Undo.RecordObject(template, "Update FSM time in file " + template.name);
ConversationTimeExtractor.ProcessTimeInFsm(ref template, inputData, utils);
EditorUtility.SetDirty(template);
My guess is that the editor is not detecting that the asset has changed, because it does not generate the Undo option. When I use “Undo.RegisterFullObjectHierarchyUndo”, the undo option is registered, but when I hit play, the object reset to previous state.
Had the same problem and could solve it. It was a Serialization issue. Maybe this can help some people.
I have a ScriptableObj ‘SoundTable’, holding an array of 'SoundClip’s, each associating an AudioClip with a string key.
For faster access I collect double entries and save them with the SoundTable. So I had a SoundClip[ ][ ] in the table. That worked mighty fine in the Editor, but didn’t survive Play Mode and didn’t save to disk.
Because it worked in Editor, i thought it was an issue with dirty flag and used SetDirty(). Didn’t work. The solution was to avoid the mulidimensional array by putting the array in an class, like this:
[System.Serializable]
public class SoundClipArray
{
public string name;
public SoundClip[] clips;
public SoundClipArray(string theName, SoundClip[] theArray)
{
name = theName;
clips = theArray;
}
}
SetDirty() now works as expected (for this use case). So the point is, serialization works different in Editor and when writing to disk. Evil trap I was falling into.