Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feedback Saving ScriptableObject but not the current scene.

Discussion in 'Editor & General Support' started by Nickromancer, Jun 2, 2022.

  1. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    The current editor implementation seems not able to save ScriptableObject without saving the editing scene.

    There is no UI to selectively save a ScriptableObject, we can only use Ctrl+S (anywhere) to save but that will also save the scene which is not desired half of the time because there could be temp stuff during editing. But without ctrl+s, merely editing the ScriptableObject setting won't save it. (confirmed it when try to commit the change with git)

    My expectation. When press ctrl+s with focus on ScriptableObject inspector, only save the ScriptableObject, preferbly provide UI to see if file is dirty and allow to be saved via UI. The current implementation like a joke to this professional software.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Try making a menu command that simply calls AssetDatabase.SaveAssets(). Maybe that works.
    Also there is (or used to be) the File—>Save Project command. Perhaps that works for this situation.
     
  3. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    Thanks for you input but whether it works or not, this post is not about finding workaround. They need to fix fundamental design issue once and for all.

    1. lack of indication about dirty file. The best they can do now is just to add a * to the hierarchy title text. Everywhere else whether it is ScriptableObject, Setting page, Addressable setting panel or whatever has no visual hint at all.

    2. unable to save a single modified file.
    Current Ctrl+S save everything, forcing user to save there scene even if they only want to save other files unrelated to the opened scene.

    The current saving behaviour need to be improved.
     
    Last edited: Jun 3, 2022
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,647
    I'm curious how many people this is an issue for? I haven't once wanted to save a particular SO and nothing else.

    If you have stuff in the scene that doesn't need to be saved, isn't that what hideFlags is for?
     
  5. Havokki

    Havokki

    Joined:
    Jun 28, 2015
    Posts:
    118
    If I want to save one asset, but not the rest, I'll just revert those in git before I commit.

    I wouldn't want to have unsaved assets anyway, since then I wouldn't see from version control whether I have made any changes to them. And if they are not there, how would I easily revert my project to a clean state? Having the inspector show a "dirty" status isn't enough either, because the changes might have been made by a custom tool or an automated process.

    Those unsaved changes would only be in memory (or library, which is ignored from VC anyway). Those changes might also affect gameplay and our tools, so I wouldn't want them to stay hidden or having to keep track of "dirty" markers around the UI.
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,647
    Yeah it sounds like a micro-management nightmare to me. This behaviour would be contrary to, well, basically every other program in existence, where saving saves the everything that you're working on.

    If I had need for more specific behaviour than that, I would implement something in the editor to accomplish it.
     
  7. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,937
    I'm curious about this expectation. What software have you encountered that has this by default? I'm working my brain trying to think of anything that I would use that would allow for saving only a small aspect of a project but I just can't think of anything.

    Edit: I just hit the post button and one example immediately came to me: Unreal.
     
    spiney199 likes this.
  8. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    Are we living in the same universe?
    Adobe Photoshop, Visual Studio, Notepad++ and many other software that support editing multiple files simultaneously basically don't save every file when you press Ctrl+S. They usually come with at least two menu options one called "Save" and the other called "Save All" (which generally have different shortcut like Ctrl+Shift+S).

    About the situation that cause me don't want to save the scene but only the other files. My game use prefabs to hold dynamic content like many other people do. During editing, I may need to load some content up in the hierarchy temporarily and edit them. In the middle of the editing, I may create and edit ScriptableObjects, addressible, etc. I would sometime like to save the progress or event commit them to git but not want the scene get saved because it is loaded with temp contents.
     
  9. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,647
    I think the parallel trying to be drawn was more that you can't save just one layer in photoshop, or just part of your text document. When you save, the whole file gets saved. In Unity's case, the whole project is the file, and everything gets saved when hitting Crtl-S.

    In your above case, it sounds like you just need a scene that's not built into the game to assemble temporary stuff.

    Again, the Unity Editor is your oyster so this functionality can easily be added.
     
  10. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    If you view your project like its a single file and it works for you, good for you. The requirement is different from project to project. The things we mentioned is literally different files for storing different settings. Obviously I could not like treating them as a single file because the "one key save them all" behaviour is affecting my workflow.

    Anyway, a good software design should provide flexibility and correct presentation. In this case, unity editor is unable to hint unsaved changes appropriately and failed to provide flexibility for saving single file. While you might suggest me to write a script to workaround the problem. In my opinion, while software could provide ways to extend its function via script/plug-ins, something as fundamental as showing unsaved changes and saving file should not be fixed by the end users. It should be supported built-in even if its not the default setting.

    Anyway[2], this is a [feedback] post and not [help wanted] post. I just came here to point out the issue and give my suggestion. Whether you agree with me or not, and have many different idea to workaround the mentioned issue. It is not important. I guess my job is done here. Have a nice day.:)
     
  11. RafalDorsz

    RafalDorsz

    Joined:
    Feb 18, 2014
    Posts:
    4
    Wait, don't SOs get serialized automagically when you edit them in the inspector the usual way?
     
  12. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    They get serialized but just in memory. Not saved to the corresponding files. It can be observed by trying to commit git. If unity crash before pressing ctrl+s, changes will be lost. I even doubt if it will auto save by just quitting the editor because I lost changes some days ago when addressable under unknown circumstances is not reacting to Ctrl+S correctly and I restarted the editor.
     
  13. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,937
    If I'm not mistaken Adobe Photoshop doesn't treat everything opened as a single project like Unity. I had forgotten about the other two but I haven't used them in years except to install SDKs in the case of the former.
     
  14. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,647
    Yeah, and Unity provides that by giving you access to a huge editor API to customise it to your heart's content. In the time it took you to make this forum post you could've made your own editor functionality and moved on.

    Hell I just did so because why not:
    upload_2022-6-3_23-36-51.png
     
    Havokki likes this.
  15. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,937
    I understand your reasoning but the problem here is that it would completely change the behavior of the editor and lead to people losing the latest changes to their scenes because they forgot to deselect the currently active asset.

    It would have to either be an optional setting or a new shortcut key.
     
    Last edited: Jun 3, 2022
  16. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    Like I said in my last response, I am not asking for workaround solution but suggesting an improvement to the editor. Congrat on your save button, are you going to inject another save button to Addressables Group panel and many other panels next?

    Of course you can. You can also help police catch theft when the police is not working. The point is "should you do it". Is it your job to add the save button or is it the unity's job to provide the save button. The save button is not the only complaint here. Unity also lack hints for dirty files.

    Yes, this can easily be avoid by not changing the default setting/shortcut but provided as configurable setting.
     
  17. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,647
    It's not a work around, it's literally a solution to your problem. You're asking for more flexibility, but it's already there. The Unity Editor is yours to extend, so go nuts.

    For example, here's literally a script that does what you want:
    Code (CSharp):
    1.         [MenuItem("Editing/Save Selected Asset(s) %#s", priority = 0)]
    2.         public static void SaveSelectedAssets()
    3.         {
    4.             if (Selection.count == 0) return;
    5.  
    6.             if (Selection.count == 1)
    7.             {
    8.                 UnityEngine.Object selectedObject = Selection.activeObject;
    9.  
    10.                 if (AssetDatabase.Contains(selectedObject))
    11.                 {
    12.                     AssetDatabase.SaveAssetIfDirty(selectedObject);
    13.                 }
    14.                 else
    15.                 {
    16.                     Debug.LogWarning("Current Selection is not an asset.", selectedObject);
    17.                 }
    18.             }
    19.             else if (Selection.count > 1)
    20.             {
    21.                 int savedCount = 0;
    22.                 foreach (UnityEngine.Object selectedObject in Selection.objects)
    23.                 {
    24.                     if (AssetDatabase.Contains(selectedObject) && EditorUtility.IsDirty(selectedObject))
    25.                     {
    26.                         savedCount++;
    27.                         AssetDatabase.SaveAssetIfDirty(selectedObject);
    28.                     }
    29.                 }
    30.                 Debug.Log($"Saved {savedCount} of {Selection.count} selected objects.");
    31.             }
    32.         }
    Requires you to unbind the CTRL-SHIFT-S Save-As shortcut (who uses that anyway?), but this will save only the selected objects should they be assets.
     
  18. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    I appreciate your effort at providing the solution. However, what I am asking for is an action from Unity that is to provide native support for something this fundamental so that everyone can have it when they need it without adding extra script files to their every projects. Please understand the difference. I am not asking for a solution and I am capable of solving it myself if I really want to. If you haven't notice from my signature, I even create a really cool console replacement with excellent features. (website: https://storage.googleapis.com/oml-console/index.html).

    Not to mention, the non-native solution you suggested only solve the saving issue. It also require user to find and select the asset instead of doing it natively from the UI panel. Yes, you have another script to attach a save button to ScriptableObject but what about other assets like addressible group panels, etc? The optimal solution including dirty file visual hint should be done by Unity side as they have full code access to all their editor panels.

    Let's end the discussion here. I only come here to give my feedback. I didn't expect to spend too much time on this discussion.
     
  19. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,647
    This kind of feature is on par with 'snap to ground' feature requests that come up regularly, which is as only essential as it is in the eye of the beholder. Of which it could be of zero importance or it could be of utmost importance. While you consider it 'fundamental' I've never even thought about such a feature until this thread.

    And while it's a small feature there's about a million ways it can be implemented, so Unity are better of letting users implement such small features to their preference. So... do it yourself and move on.