Saving and loading state

On emulators you can save state and load state. I am wondering how to implement this in my game for unity. I have figured out how to use ployerpref for saving and loading which worked great for my other game. Thanks again everyone.

You can't really use the same method as generally used in emulators to snapshot the entire state of the game.

With emulators, they generally capture a snapshot of the entire rom and ram state of the machine at that moment in time. This is possible because generally the amount of space (in data) that these old machines and programs occupy is relatively tiny, and so it is feasible to simply save this entire state as a single file. In modern computers and unity projects this data could amount to hundreds of megabytes, and there's no simple way to capture the entire state, so you have to decide on a small sub-set of information to store, and implement a method to capture and restore just these important things that you choose.

To create a "snapshot" style save function in a Unity game you would have to save the position and rotation of all the important moving objects (player, enemies, collectible items, doors opened/locked, etc), and all the dynamic values that you care about (Score, Lives, Energy of Player and Enemies, etc).

You'd then need to serialse this data into some easily readable and writable format (eg, XML, or JSON), and dump this into either PlayerPrefs or a text file using the File IO functions (if you are building a Mac/PC executable build).

Finally, you'd need to write a system which can read these values back, and reposition every item accordingly, and restore all the recorded values.

All-in-all, not a trivial task, but certainly possible! Good luck!

This works really well to solve this problem. It’s not Unity built in but is great.

Duck’s answer is correct too for the record.

You can save and load state of a Unity app, but for debugging purposes: