Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Play Mode Save

Discussion in 'Assets and Asset Store' started by pluginmaster418, Aug 20, 2020.

  1. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188


    This tool allows you to save changes made in play mode.

    Features
    • Save changes made in play mode to any component, built-in or custom.
    • Save a snapshot of the values of the component.
    • Save the values of the component as they are when exiting play mode.
    • Save the values of SriptableObjects immediately.
    • Auto-Save.
    • Save all components in a game object and its children.
    • Save objects created in play mode.
    • New features are continuously added based on user requests.
    Limitations
    • Only works on Unity 2019.2 or higher.

    How to use:
    1. In play mode. Right-click on the component to open the context menu.
    2. Click Save Now or Save When Exiting Play Mode.

    Links:

    Asset Store
    Documentation

    Please post any feedback, suggestions or ask for support or missing features here.
     
    Last edited: Sep 9, 2021
    metalblinga, tom532, Majistic and 3 others like this.
  2. Gramms66

    Gramms66

    Joined:
    Aug 15, 2017
    Posts:
    31
    Nice extension!

    I think adding a checkbox as well for auto-saving (only on edit of course) would make it even more useful.
     
    jmcusack likes this.
  3. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey thanks for the suggestion, it had occurred to me too, but the thing is, making the data in edit mode persist in play mode is a bit tricky. But your suggestion encouraged me to find a solution and I already came up with a trick to make it work.
     
    jmcusack and Gramms66 like this.
  4. ZeHgS

    ZeHgS

    Joined:
    Jun 20, 2015
    Posts:
    117
    Very useful! However, the auto-saver is not working for me. What could it be?

    Also, can I apply changes made from code as well once the auto-saver works again? I've been trying to get the auto-saver to work myself but I don't know how to keep track of the changed objects in the editor script once play mode exits.

    EDIT: Actually never mind. This one worked https://assetstore.unity.com/packages/tools/utilities/persistent-components-59009. Thanks anyway!
     
    Last edited: Oct 31, 2020
  5. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey, at the moment PlayModeSave is not designed to work as you think. Right now, the tool allows you to take a snapshot of a transform and save it when exiting play mode. No matter how you modify the transform after saving it, it only keeps the values you saved before and applies them when you exit play mode. However, I think I'll add the option to save the transform values as they are just before exiting play mode, or in other words make the transforms persistent.

    BTW, the tool you mention looks great and allows you to make other components persistent not just transforms. But if what you need is to take a snapshot, you can use PlayModeSave.
     
    ZeHgS likes this.
  6. ZeHgS

    ZeHgS

    Joined:
    Jun 20, 2015
    Posts:
    117
    Thank you for your reply!

    Got it! I would love it if you could make the transform values persistent in such a way that I could run the program, make the changes I want through code alone, then simply exit play mode. The other tool seems amazing but it actually caused some problems with other things that should not have been affected.

    If you make these changes in the next couple of days please do let me know because it would be very useful to me!
     
  7. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey, version 2.0 is available and now you can save changes made in play mode to any component, built-in or custom. You can also save component values as they are when exiting play mode (that is, persistent components until exiting play mode). Check it out.
     
    ZeHgS likes this.
  8. ZeHgS

    ZeHgS

    Joined:
    Jun 20, 2015
    Posts:
    117
    Awesome, thanks!
     
  9. leavittx

    leavittx

    Joined:
    Dec 27, 2013
    Posts:
    176
    Hi there! Thanks for your asst.
    Is it possible to use your asset to save ScriptableObject changes in Play Mode (i.e. "Save Now") ?
    If not, would it be hard to add such feature? Would really appreciate it
     
  10. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey, I'm sorry, but I think I'm not understanding what you want to do. ScriptableObjects are assets, so they are persistent between sessions and do not need to be saved. Play Mode Save only saves changes to serializable components, that is, all built-in components and custom components with serialized fields. However, the tool has a limitation: It does not save changes to objects and components created in play mode. Is this limitation related with you want to do?
    Could you please explain your case more specifically in order to understand what you want to do.
     
  11. leavittx

    leavittx

    Joined:
    Dec 27, 2013
    Posts:
    176
    I have a class which is derived from ScriptableObject and an asset of such type.
    During the play mode I'm able to modify its fields and later, upon exiting the play mode its contents are being serialized by Unity and saved to the corresponding asset.

    However if Unity crashes or hangs because of some problem (that can happen for example after even a small change to a C# script), its contents are not being saved, and all my work is lost.
    Thus, it would be awesome to be able to "Save now" such an asset during the play mode or (that one is optional) configure an auto-save (with some period of time or after each change).

    I think the code can be found here: Saving SerializedObject assets in play mode? : Unity3D (reddit.com)
    Code (CSharp):
    1. AssetDatabase.Refresh();
    2. EditorUtility.SetDirty(level);
    3. AssetDatabase.SaveAssets();
    However I'm not sure how to use it in a proper way in such scenario, and maybe it would be useful to include it to your asset for the sake of completeness
     
  12. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey. Now I understand what you want to do. Ok, I will add that functionality to the tool in the next version. In the meantime, check if this works:
    Code (CSharp):
    1. [MenuItem("CONTEXT/ScriptableObject/Save Now", false, 2000)]
    2.         private static void SaveScriptableObject(MenuCommand command)
    3.         {
    4.             AssetDatabase.Refresh();
    5.             EditorUtility.SetDirty(command.context);
    6.             AssetDatabase.SaveAssets();
    7.         }
     
    leavittx likes this.
  13. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Version 2.1 is now available. Now you can save ScriptableObjects.
     
    leavittx likes this.
  14. leavittx

    leavittx

    Joined:
    Dec 27, 2013
    Posts:
    176
    Ok, I can confirm it's working now! So nice!
     
  15. leavittx

    leavittx

    Joined:
    Dec 27, 2013
    Posts:
    176
    Btw just wondering whether you have any plans on implementing some of these features:
    - auto-save with some period of time (optionally enabled) - can save work in case of crashes and if you forgot to "Save now"
    - a custom "Save" button (which may change the color depending on whether any changes were made since the last save)
    upload_2021-1-19_18-11-40.png
    that way it's easier to remember that you might need to save the changes

    Thank you!!!!
     
  16. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Glad to hear that the new feature is working.
    About the new features you mention, I'll keep them in mind for future versions.
    Thanks for helping me improving the tool.
     
    leavittx likes this.
  17. lorenzoteslermabe

    lorenzoteslermabe

    Joined:
    Dec 23, 2020
    Posts:
    24
    Hey this is cool! I am trying to change sorting layers on a sprite renderer and unfortunately the changes don't get saved.
     
  18. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    You're right, unfortunately it seems like that property doesn't have a serializable backing field. But I can fix it. It will be available in the next version.
     
  19. lorenzoteslermabe

    lorenzoteslermabe

    Joined:
    Dec 23, 2020
    Posts:
    24
    Awesome thanks! Ya I would love to use your asset as it seems immensely helpful, but hopefully you can understand that if I'm not sure which aspects of components will or will not be saved, then that uncertainty renders it to a large extent unusable. Looking forward to trying the next version though and will be following the progress! Cheers.
     
  20. lorenzoteslermabe

    lorenzoteslermabe

    Joined:
    Dec 23, 2020
    Posts:
    24
    Sorry for the double post... I realize I spoke a bit in hyperbole there. It's not that big of a deal to keep a closer eye on what's being saved, and I just wanted to say that the speed of that update today was awesome. Appreciate it!
     
  21. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Version 2.2 is now available. these are the new features and fixes:
    • [Added] Auto-Save Functionality.
    • [Added] Functionality to save the sorting layer property on SpriteRenderer components.
    • [Fixed] Issues when saving and loading editor preferences.
    Feel free to report any issues with unsaved properties on built-in components. All comments, suggestions and bug reports are welcome.
     
    ledshok likes this.
  22. alkanyay56

    alkanyay56

    Joined:
    Mar 29, 2020
    Posts:
    1
    It doesn't work with Feel package's MMFeedback component
     
  23. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    The problem is that I don't have the feel package, so I can't test it here. But I think the issue may be that there are attributes in the MMFeedback component that are not being serialized.
     
  24. tootyboi

    tootyboi

    Joined:
    May 9, 2019
    Posts:
    7
    Hi,

    I recently purchased your asset, but it doesn't seem to work on my project for some reason.

    https://drive.google.com/file/d/1HJYLHQqf6xNxjbNwL_KZlFc0BbcmP04F/view?usp=sharing

    In this video, I actually did right-click the transform component, and click 'Save now', just that it did not show up in the video for some reason. But you can see the red icon in the hierarchy indicating so. However, the transform isn't saved after Play Mode has ended.

    I wonder if I am doing anything wrong? I restarted Unity after the import but it still doesn't work.

    Looking forward to hearing from you, thanks.

    P.s. I am using Unity 2019.4.20 LTS
     
    Last edited: Jul 26, 2021
  25. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hi,
    It's strange, it may be that another script is resetting the position. Does the problem occur with all the objects or only with the river?
     
  26. tootyboi

    tootyboi

    Joined:
    May 9, 2019
    Posts:
    7
    Hi,

    Yup it seems like this problem affects all other gameobjects. I tried it in other scenes too and it persists. Could it be some sort of project settings?

    EDIT: Weird. When I tested this asset on a brand new scene, it works perfectly. My gut feel is that this package somehow clashes with some existing package.
     
    Last edited: Jul 27, 2021
  27. tootyboi

    tootyboi

    Joined:
    May 9, 2019
    Posts:
    7
    For some strange reason, I noticed the following:

    1) The saved object is properly serialized and stored in the Dictionary "_compData[key]"
    2) This data persists even until the Unity Event "state == PlayModeStateChange.ExitingEditMode" (Refer to ref1.png)
    3) This serialized data is somehow "null" by the time it got to "state == PlayModeStateChange.EnteredEditMode" (Refer to ref2.png)

    It seems as though all data on serializableObject are cleared upon exit from Play mode.
     

    Attached Files:

    Last edited: Jul 27, 2021
  28. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    The weird thing is that ExitingEditMode should be triggered only when you press the play button to enter play mode.

    The correct sequence of events should be as follows:
    1. In edit mode, click the play button to enter play mode.
    2. The state changes to ExitingEditMode
    3. The Editor enters play mode and the game starts to run.
    4. The state changes to EnteredPlayMode.
    5. Click on "Save Now". The changes are saved.
    6. Click the play button to exit Play mode.
    7. The state changes to ExitingPlayMode.
    9. The Game stops playing and the editor enters edit mode.
    10. The state changes to EnteredEditMode. The changes are applied.

    If _compdata is null when entering edit mode, then something strange is happening and you are the first person to experience such behavior. However, I will try to prevent that from happening by saving the changes to a file to ensure persistence.
     
  29. tootyboi

    tootyboi

    Joined:
    May 9, 2019
    Posts:
    7
    Ah the sequence of steps are exactly as you have described.

    Could you offer any code snippets or hints to allow for 'saving the changes to a file to ensure persistence'? I am confused by how that works. Since the reference to the serializableObject is now 'null', there is no way to refer back to that specific object in the game even if you have all its information cached in a file.
     
    Last edited: Jul 27, 2021
  30. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Please contact me by email (pluginmaster418@gmail.com) to send you the repaired file when it is done.
     
  31. tootyboi

    tootyboi

    Joined:
    May 9, 2019
    Posts:
    7
    Ok sounds great. Just sent you an email.
     
  32. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey, I sent the file to your email. If it doesn't work, it occurs to me that it could be due to a scene management script or another script that is cloning the entire hierarchy and deleting the original objects and for that reason the targets of the SerializableObjects become null when exiting play mode.
     
  33. dinhcuong235

    dinhcuong235

    Joined:
    Apr 8, 2021
    Posts:
    13
    Hi pluginmaster418,
    I just paid for your product. It works perfectly on the 2020 version but on the 2018 version it crashes. Do you have any suggestions for me. I really need it for this project. Thank you.
     

    Attached Files:

    Last edited: Aug 15, 2021
  34. dinhcuong235

    dinhcuong235

    Joined:
    Apr 8, 2021
    Posts:
    13
    In the meantime I have tried upgrading to NET4.0 which is level 4.0. This way fixes some library errors. But there is still 1 error related to API
     

    Attached Files:

  35. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey, Please contact me by email (pluginmaster418@gmail.com) to send you a file that works on Unity 2018. Some Features wont be available: Persistence between sessions.
     
  36. dinhcuong235

    dinhcuong235

    Joined:
    Apr 8, 2021
    Posts:
    13
    I sent a letter for you. Please send me help. Thank
     
  37. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Done, I just sent the file to your email.
     
  38. dinhcuong235

    dinhcuong235

    Joined:
    Apr 8, 2021
    Posts:
    13
    I tried and it doesn't work when switching scene
     
  39. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Fixed but only works in Unity 2019.2 or higher. Will be available in the next release.
     
  40. sjyooon

    sjyooon

    Joined:
    Feb 6, 2016
    Posts:
    3
    Can I save changes made in scenes that was loaded dynamically by code?
     
  41. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Yes, that feature was added in version 3.1. After exiting play mode, scenes with changes are opened in edit mode so you can apply the changes automatically or manually.
     
  42. PinkFluff432

    PinkFluff432

    Joined:
    Aug 1, 2021
    Posts:
    2
    I DID 50 MINUTES OF WORK THEN I REALIZED IT WAS ALL GONEEEEEEE BECAUSE I WAS IN PLAY MODE WHYYYYYYYYYYYYYYYYY
     
  43. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey, I'm sorry you lost so much work, I know how frustrating that is. Could you tell me how you used the tool to save the changes you made in play mode?
     
  44. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    1. Are you planning on implementing the saving of created objects as well?
    2. Are there any problems with additive and/or async scenes?

    Thank you.
     
  45. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    1. I've almost finished the functionality to save the created objects.
    2. So far there are no problems with additive and / or asynchronous scenes.
     
    starikcetin likes this.
  46. unity_RMiJ7SENDRQxhQ

    unity_RMiJ7SENDRQxhQ

    Joined:
    Oct 5, 2018
    Posts:
    8
    I can't see a feature to save and load for individual gameobjects. its either you save single component or save the whole gameobject hierarchy.
    Also, what If I add a component in runtime. It doesn't get added when I hit apply changes.
     
    Last edited: Oct 16, 2021
  47. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hi, you are right, those features are not implemented yet. I'm going to add them to the next version. I'll let you know when it's ready.
     
  48. unity_RMiJ7SENDRQxhQ

    unity_RMiJ7SENDRQxhQ

    Joined:
    Oct 5, 2018
    Posts:
    8
    How much time will it take?
    My project is in halt due to that. these are easy features Imo and shouldn't take long.
    Anyway, take your time and give me some estimate so that I can schedule my work that way.
    Regards
     
  49. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    188
    Hey. I submitted the new version yesterday so I hope it will be available tomorrow or Tuesday. Email me at pluginmaster418@gmail.com to send you the new script.
     
  50. vincurekf

    vincurekf

    Joined:
    Jan 3, 2014
    Posts:
    10
    Hello, I have noticed an issue while trying to build scene with objects being marked as "always save when exiting play mode". After entering play mode at least once and then trying to build the scene, the build fails with this error message:

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. PluginMaster.PlayModeSave.Apply (PluginMaster.PlayModeSave+ComponentSaveDataKey key) (at Assets/PluginMaster/PlayModeSave/Editor/Scripts/PlayModeSave.cs:635)
    3. PluginMaster.PlayModeSave.ApplyAll () (at Assets/PluginMaster/PlayModeSave/Editor/Scripts/PlayModeSave.cs:659)
    4. PluginMaster.PlayModeSave+ApplicationEventHandler.OnSceneOpened (UnityEngine.SceneManagement.Scene scene, UnityEditor.SceneManagement.OpenSceneMode mode) (at Assets/PluginMaster/PlayModeSave/Editor/Scripts/PlayModeSave.cs:833)
    5. UnityEditor.SceneManagement.EditorSceneManager.Internal_SceneOpened (UnityEngine.SceneManagement.Scene scene, UnityEditor.SceneManagement.OpenSceneMode mode) (at /home/bokken/buildslave/unity/build/Editor/Mono/SceneManagement/EditorSceneManager.cs:49)
    6. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /home/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
    Only thing that helps is to manually remove the "always save" flags from every object, but these are now invisible in edit mode, so I have to go from memory and check every object if it is or is not set to save changes from play mode.