- Home /
Saving a scene within the game?
Hi,
I'm nearing completion of my project now, and have begun work on a map creation tool. It's a fairly simple one at it's core, it allows you to place pre-made prefabs on a grid, to create a map.
However, I now want to be able to save the maps I create in the map creator. i want to save them as an entire scene, but without the Map creation object that was used to make it.
Is there some unity reference for saving to a scene file, and similarly can I do somehting along the lines of:
Unity.BeforeSaveScene () { destroy (Map creation unit); }
Unit.SaveScene;
You can't save scenes at runtime. You need to use an editor script for this.
If you save the file as some other format which gets loaded in using file IO methods and then parsed into an actual level, you can do that at runtime. However, this doesn't use the full functionality of the Unity editor, unless you write that yourself.
Good question. I also want to create a standalone EXE level editor, to let people edit levels, and save unity scenes (and not custom files that represent the scene).
This is something I wish the Unity $$anonymous$$m would enact. I create a scene fabulously and easily with the editor, then my character/player runs around and moves things/destroys things. Why wouldn't they give us the ability to SaveAs that scene during runtime?
Sure, I can write a very simple script that will foreach every single gameobject and output is essential data, but it just seems to me like this should be inherent using the built in scene loaders.
Answer by NextGenGameDesigner · May 23, 2012 at 06:59 PM
You can't save scenes but you can have saves of custom maps using file IO in the same exact scene every time. A example would be:
1.On save map store the prefabs Vector, and names in a file. 2.On map load read the file and instantiate prefabs accordingly.
The save file could look like this:
//Prefab Vector3, name, and Rotation 0,0,1 "crate" 0,90,10 1,0,1 "ladder" 0,50,0 0,2,1 "wall" 50,20,0 7,0,1 "building" 0,10,0