Search Issue Tracker
Won't Fix
Votes
0
Found in
2021.3.40f1
2022.3.35f1
6000.0.8f1
7000.0.0a1
Issue ID
UUM-74622
Regression
No
EditorUtility.SetDirty doesn't always lead to Save and AssetDatabase.SaveAssets occasionally fails in case of ScriptableObjects
How to reproduce:
1. Open the “SetDirtyBug“ project
2. Open the “SampleScene“
3. Duplicate the “Assets/My Scriptable Object.asset“ in the Project window
4. Open the “Assets/My Scriptable Object 1.asset“ in a Text Editor
5. Open the “Assets/My Scriptable Object 1.asset“ in the Inspector
6. Observe the “myVariable“ field in the Text Editor and the “My Variable“ field in the Inspector
Expected result: The “myVariable“ field and the “My Variable“ field have the same value
Actual result: The “myVariable“ field and the “My Variable“ field have different values
Reproducible with: 2021.3.40f1, 2022.3.35f1, 6000.0.8f1
Reproducible on: macOS 14.5 (Intel), Windows 10 Pro (22H2)
Not reproducible on: No other environments tested
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
- Crash on when D3D12RenderPass::SetupDeviceResources when opening FBX animation preview
- Serialization errors are thrown when "com.unity.render-pipelines.core" is added as a custom package and Graphics window is opened
- Character Joints unexpectedly rotate when a ragdoll is created using the Ragdoll Wizard
- Crash on GfxDeviceD3D11Base::DrawBuffersBatchMode when rendering the Scene view
- The shared EditorBuildSettings.asset file of symlinked projects is not updated when changing the order of the Scenes in Build Settings in one of the projects
Resolution Note:
Hi!
The reason why the value does not match up in the asset file and the inspector, is because the value is never saved. In most cases you can fix this by calling AssetDatabase.SaveAssets after setting the field dirty. In this particular example, that might lead to a problem, because AssetDatabase.SaveAssets is not recommended to be called inside OnValidate. OnValidate can be called often, and also during serialization, which is not supported for AssetDatabase.SaveAssets.
I have moved the logic to run on a button press with an extra AssetDatabase.SaveAssets line to make sure there is no other underlying issue, but it seems like it works as expected. If you still have problems with this after saving and moving this logic out of OnValidate please let us know.