Search Issue Tracker
By Design
Votes
0
Found in
2019.1
2019.1.5f1
2019.2
2019.3
2020.1
Issue ID
1182899
Regression
No
Undo.RecordObject creates an undo entry, but no changes are recorded to file when saving project until undo/redo is made
To reproduce:
1) Open the attached project and scene
2) Open ScriptableObjects/MyScriptableObject.asset in Notepad++ or a similar app (key requirement: Be able to observe when changes are made to the file)
3) Select Tester in Hierarchy
4) Click Add Random Name in Inspector
5) Click File -> Save Project in top menu bar
Actual: There are no changes to MyScriptableObject.asset
6) Click Ctrl+Z and Ctrl+Y to undo the name addition and redo it back
7) Save the project again
Expected: Now the asset saves the change
Reproduced in 2019.1.0b1, 2020.1.0a4
-
keni4
Jul 19, 2023 11:30
I've got this bug on unity 2022.3.1... gj
-
huulong
Dec 14, 2022 17:24
pitchblende is right, I submitted another bug report explaining things in details.
-
pitchblende
Mar 16, 2021 23:02
No, the real issue is with the documentation - it specifically says here: https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html
"If you do want to support undo, you should not call SetDirty but rather use Undo.RecordObject prior to making changes to an object, since this will both mark the object as dirty"
It stats that Undo.RecordObject should mark an object as dirty (so that a Save will write changes to disk), but this does not happen! As the original reporter says, a weird workaround is to do an Undo operation first, and then it does write to disk on Save.
The current workaround is to call both Undo.RecordObject (to create the Undo record), then make the change to the ScriptableObject, and then call EditorUtilities.SetDirty to ensure the change is written to disk on Save. The documentation should make this clear.
I've reproduced this in 2020.2.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- "Problem detected while importing the Prefab file" errors on Learning Templates import
- Crash on RaiseException during Socket.BeginConnect in Player when application connection is blocked through commercial firewall
- Decal Projector produces artifacts when the normal and decal are projected in negative z-direction and Normal Blend is set to 1
- Undoing slider field change only resets slider position, doesn't undo the value change
- Precision changes when a tangent is added to a Vertex node
Resolution Note (2020.1.X):
It's an issue with user project. Scriptable object is modified by user script, but it doesn't mark the asset as dirty, thus Saving Project doesn't save the asset. Undo/Redo simply marks the asset dirty, it has nothing to do with saving. Marking asset dirty whenever the button is pressed should fix the problem