Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    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:
    60


    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
    AlterMannn and Lars-Steenhoff 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:
    60
    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:
    49
    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:
    60
    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:
    49
    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:
    60
    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:
    49
    Awesome, thanks!
     
  9. leavittx

    leavittx

    Joined:
    Dec 27, 2013
    Posts:
    114
    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:
    60
    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:
    114
    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:
    60
    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:
    60
    Version 2.1 is now available. Now you can save ScriptableObjects.
     
    leavittx likes this.
  14. leavittx

    leavittx

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

    leavittx

    Joined:
    Dec 27, 2013
    Posts:
    114
    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:
    60
    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:
    16
    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:
    60
    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:
    16
    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:
    16
    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:
    60
    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:
    60
    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:
    60
    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:
    60
    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:
    60
    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:
    60
    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:
    12
    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:
    12
    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:
    60
    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:
    12
    I sent a letter for you. Please send me help. Thank
     
  37. pluginmaster418

    pluginmaster418

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

    dinhcuong235

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

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    60
    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:
    1
    Can I save changes made in scenes that was loaded dynamically by code?
     
  41. pluginmaster418

    pluginmaster418

    Joined:
    Jun 6, 2020
    Posts:
    60
    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:
    1
    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:
    60
    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:
    295
    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:
    60
    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.
unityunity