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

Asset - Database

-

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

  1. 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

Comments (3)

  1. keni4

    Jul 19, 2023 11:30

    I've got this bug on unity 2022.3.1... gj

  2. huulong

    Dec 14, 2022 17:24

    pitchblende is right, I submitted another bug report explaining things in details.

  3. 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

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.