How to Save Game State (new objects) to Unity Scene

We have added a mechanism as part of gameplay where a hot-key drops in a Viewpoint, which is then saved to a Text Asset that can be used later (where it's saved/loaded to this Text Asset).

Ideally, though, we would RATHER find a way to add these new GameObjects (viewpoints) to the actual Unity Scene.

Desired Workflow: 1. Run/Play Scene ("Game" mode). 2. Press Hot Key to start "Viewpoint Recording". 3. Move player around, and capture View Points with "V" hot key. 4. Press "escape" to stop this recording, and save the result. 5. Ideally, this would be saved to actual Unity Scene -- so that we can now "doctor it up" in Scene Design mode. I want to see these new Viewpoint GameObjects in Scene Editor mode, and when I save the scene, I want to have these objects saved with scene.

Currently, the default behavior is that all new objects are lost when you stop the game play.

I think a custom editorwindow would be a good candidate to solve this. You could give it a button (or have it respond to the "v" button). when that gets clicked, it could remember the position & rotation. when you're all done, stop the game, (the editorwindow still remembers all its info), and have another button in the editor window that says "Create camera gameobjects from remembered positions". Which basically does just that. you click that button when the game is not playing, so they will get saved in the scene.

Here is the simple solution that I am hoping you have not tried:

While in play mode, select the objects. Copy them. End play mode. Paste. Done.

The only part of this that requires many clicks is the selection process, but you could have your existing editor script make them a child of some other node to make that easier, or you could make a separate editor script to do the selection for you if it is that complicated.

I sort of liked what Lucas said, but his answer was not voted up so I will give it shot. Maybe we don't understand the question.

We had (I think) a similar problem. If you want to save data in scene edit mode like camera orientation or points of interest you could store those in a model object (Viewpoint?) and then use a persistence mechanism (like YAML or XML) to persist out the interesting parts of the Viewpoint or whatever it is you are capturing. These can then be edited and changed elsewhere. At run time you load these and use them. I am not clear why they would have to be on the scene graph but if you wanted to do that (say, if they need to be "update"ed) you could systematically create a container GameObject and plant your Viewpoint in that.

Sounds like a viewpoint is maybe a predefined point of interest plus a camera definition/orientation? If so the above should work and you really don't need a GameObject instance to define that unless you wanted to use the GameObject's actual position in the game as the logical POI.

Hope this helps.

I haven't done this before, but I have a feeling you could do this using some of the functions found here:

http://unity3d.com/support/documentation/ScriptReference/EditorUtility.html

In particular, you probably want to instantiate all your "view points" as children of a single parent gameobject, then create a new prefab and then assign the parent gameobject to that prefab.

You might then be able to manually place the prefab into the scene at editor time, after you've finished creating it.

This is a guess, and a suggestion of where you might find the solution based on skimming the docs! please take others' advice if someone posts an answer having 1st hand experience of doing this!