Save Scene State

Hey all, I’m working on a puzzle game where objects get moved around in the scene. The scene has 4 ‘states’ where you are given access to about a dozen objects to move around before leaving the level and then coming back to it later.

I was wondering how I can best set up, save and load these states so you could go into a debug menu scene, select the state of the scene you want to go in to, and then load it up?

Update: Thanks for the suggestions guys, but I couldn’t see either DontDestroyOnLoad or PlayerPrefs working very well for the scenario I’m working with. I instead went with a bit of code that just moves the objects into their solved positions during Start() based on the scene state.

//Go through all the pickup+putdown objects and if they've already been solved, move them to their solved position
for(var riddlePreSolved : GameObject in GameObject.FindGameObjectsWithTag("Pick"))
	if(riddlePreSolved.GetComponent(ObjectScript))
		if(riddlePreSolved.GetComponent(ObjectScript).riddleNumber < RiddleState.riddleState)
		{
			riddlePreSolved.GetComponent(ObjectScript).pickTarget.transform.parent = riddlePreSolved.transform;
			riddlePreSolved.GetComponent(ObjectScript).pickTarget.transform.localRotation = Quaternion(0,0,0,0);
			riddlePreSolved.GetComponent(ObjectScript).pickTarget.transform.localPosition = Vector3(0,0,0);
		}

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

You could also mark each object with DontDestroyOnLoad(obj) as you create it. This preserves state for that scene under the following conditions:

1.) Anything in the heirarchy will be created each load. So don’t preserve anything that isn’t dynamically (procedurally) loaded. If it’s in the heirarchy and you load the scene 3 times, you’ll end up with 3 of whatever is in the heirarchy.

2.) You have to destroy each object when you’re finally done with that scene.

So, for example, I only have the main camera in my Space scene. I dynamically load everything else into an array of GameObjects and mark it DontDestroyOnLoad. If I want to load a new set of objects into the scene, I destroy the objects in the array and reload. I can switch in and out of that scene as long as I want and everything is preserved (rotation/position etc). The camera is the only thing that resets.