I am creating a custom level editor in unity in play mode, I have already done enough, but now I would like to save all this in order to download it later. I found an option using BinaryWritter, but as I understand it, this is suitable if you want to save something simple enough. My objects have varying degrees of nesting and they have internal components to work with them. Is there some simple way to save a new scene of a scene created through code? Or the option that I manually create a scene in advance and change it in Play mode in every possible way, and then save it? It seems to me that the decision to save scene objects by parsing their values into a certain text file json/xml/ plain text file looks at least bad and too difficult for such, as it seems to me, an ordinary task.
It’s no different than load / save of an actual game… you need to capture everything about the state to allow your code to recreate the level that the user created the next time you run.
In other words, 100% of what you need to save / load a game is required for your solution. Yes you could start from a known base of a level, but the actual user-created content will always need to be saved / loaded in some way.
Load/Save steps:
An excellent discussion of loading/saving in Unity3D by Xarbrough:
Loading/Saving ScriptableObjects by a proxy identifier such as name:
When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object.
Instead you must first create the MonoBehaviour using AddComponent() on a GameObject instance, or use ScriptableObject.CreateInstance() to make your SO, then use the appropriate JSON “populate object” call to fill in its public fields.
If you want to use PlayerPrefs to save your game, it’s always better to use a JSON-based wrapper such as this one I forked from a fellow named Brett M Johnson on github:
Do not use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.
I found a relatively simple way, I save numeric values such as position, rotation, scale, etc. to a json file. After that, by reading the saved file, I load objects from resources, although I do not know how correct this is. In this way, I don’t need to take care of the internal components, since I literally create prefabs of the objects I need, and if necessary, I change their specific state (switch certain components).