After a huge amount of work by my beta testers I’ve decided that Unity Serializer is ready for version 1. Unity Serializer is a FREE save game manager that will store the state of your game so that a player can return later and continue from where they left off.
EDIT: Here is a video of US 2.2 being used to add save game functionality to AngryBots.
You can get Unity Serializer on the Asset Store, the latest documentation and versions are available on my website.
How would I handle objects that aren’t always there - for example, my game instances various enemies. Do I put them under a particular parent or something?
There’s a default implementation that uses PlayerPrefs but the core Serializer produces a compressed string so it is easy to store saved games anywhere including a server.
yes. i need to save and restore a monobehaviour object on design time, not the all game. i tried to examine your code, but it is so detailed so it will take long time to find how you did it. so could you tell the method(serialization?reflection?) to save it?
UnitySerializer will also serialize MonoBehaviours at edit time if you need it to. Subject to the scene having the requisite SaveGameManager and the components being decorated with storage scripts.
Here’s the simplest way I can think of - US does more than this. Basically if you don’t care about performance and references then you would reflect to find all the fields (and properties if you like). Perhaps then assign them to a Dictionary keyed off the name, then use BinaryFormatter to serialize the dictionary.
References
If this is always going to happen in the Editor then you could save references by detecting whether the property being saved is a GameObject or a Component and then save some special class to fix it up afterwards. For example you could use AssetDatabase.AssetPathToGUID to get the GUID of the associated GameObject in the project and then store the typename of the component you want to get on it. That doesn’t work so well for Scene items unfortunately where all you really have is the InstanceID - but that can change between sessions so would not be robust. If that doesn’t work for you then you haven’t got much choice more than updating the name of every component to be “unique” to that you can find it with its name path. US doesn’t do that (it adds a UniqueID component which you could also do), but the idea is sound (and it once worked that way, but its ugly).
This is amazing. I am creating a prefab in my game. How would I “Store Materials” and “Store Information” on it? How would I add that on the object in javascript?