I am releasing on 100% free public MIT license my code for generic level serialisation and Load/Save game features.
The code is currently in beta (it works fine for me, but will probably have some limitations).
UnitySerializer is a full level serialisation plug in. It enables you to save the progress of a game and restore it at some point in the future. It does this with minimal impact on the design of your game and requires minimal modification to your behaviours and classes.
UnitySerializer has been tested working on iOS and should work fine on Droid.
The serializer supports storing newly instantiated prefabs, as well as the status of existing scene objects (such as those that might be destroyed during the course of a game).
UnitySerializer supports the serialization of your custom classes and properties as well as most standard Unity components including
Animation support
Rigidbody support
NavMeshAgent (although the agent must recalculate its path on restoration)
Transform – including parent/child relationships
If you need path following you can use the code found elsewhere on my blog which will resume fine.
In addition, presuming you use my extended coroutine start functions, all of your coroutines will continue executing from the point that they left off and will be restored with all local variables intact. You need make no changes to your coroutines – just to the way that you start them.
The status of your level is stored in a string which can be placed in PlayerPrefs – stored on a server or in a file.
Nice job, I’ll check it right now. Thank’s for sharing.
Edit : There’s something going wrong. I got an error with UniqueIdentifier.cs. Looks like it doesn’t do the job as expected at line 90 (FixName function) :
var p = gameObject.LastAncestorOfType();
The result is that generated cubes are not saved and Console is flooded by LogError(). Obviously no one of the GameObjects is saved.
Edit 2 : The package works fine on a brand new empty project. Maybe something wrong with my previous project settings.
Is there any way (using tags or layer) to ignore some GameObjects during save instead of just ignoring their scripts ?
So I’ve updated the small download package and added a new static event to LevelSerializer called Store. It is passed the GameObject and a bool which you can set to false to stop that particular object from being Serialized. Let me know if that works for you and I’ll roll it through the rest of the examples.
EDIT Uploaded the wrong project - NOW the small download has the Store event.
Yes it can save references to any component on another game object or game objects themselves. Referenced game objects must have one of the storage scripts attached. If it just needs to hold a reference then UniqueIdentifier is enough - often of course a referenced game object will be storing its own information and hence nothing else will be required.
Actually I’ve posted a complete project example which has a lot of object references. It’s basically a simple NPC example where the characters collect items and deliver them. It’s what I use as a test harness because it needs reasonably complex custom classes, generic dictionaries etc. And of course a lot of references to world objects. It’s huge because I just zipped the project directory, but it can be found here
Yes it works fine on iOS - I’m using it on the iPhone myself.
IOS is a bit of a challenge due to AOT compilation - but I think I’ve caught all of the cases - if I haven’t then it will be easy to fix. As I say - my game works fine so most cases should be tested.
Apologies to anyone who tried to download the files in the last few hours - I had a problem with my file host and they dropped all of the links - apparently so many people downloaded stuff that I blew a bandwidth allowance I didn’t know I had. I have now hosted 2 out of 3 of the files with a new host (unlimited bandwidth!) and the large test harness should be available in an hour or so.
I’ve released a new version that has an extra filtering event for the items being stored and also added a PlayMaker addin that will store the variables and states of PlayMaker Finiite State Machines attached to game objects. As before it is available from here
A major new release has been made - now supports referencing AnimationClips, AudioClips, Meshes and Materials. Supports complex changes to hierarchies during execution and no longer requires objects to have unique names.
New GUI while loading.
As always the latest version - including new versions of the Example Project and the Test Harness are available from here.
So I’m wondering whether it makes sense to release this project on the Asset Store when it’s had a couple more weeks of testing. I’ve always released MIT licensed stuff on my blog before, but with Unity it feels like it should be an Asset Store download.
So what I’m wondering is:
Is it easy enough to contribute new versions that it won’t be a pain given I’m not making any money?
Is the Asset Store licensing compatible with the MIT license that I offer the project under at the moment?
In addition I’ve got a FABRIK based IK Solver project and a State Machine/Blackboard Expert project that I’m considering releasing as fee based assets - so I’m probably going down the Asset Store route anyway at some point. Although I’ve been wondering about releasing those as MIT licensed assets and charging for the demos and extras like iTween.
Just downloaded, that looks very very useful with the added bonus of PlayMaker support. Thank you for making sharing that… I guess saved data might be quite big, how’s the save load speed on iOS android?
I’m sure you’ve seen this already, but just in case…
The answer is “I don’t know” for enough target cases yet - it is fine on my game, but I might want to improve the performance. I’m hoping to get some feedback and optimize where I need to.
I only write PlayerPrefs at the end of the serialization process - but that process is quite heavyweight anyway (certainly the first time as it has to go and discover all of the properties of all of the classes that are fed into the stream and encode their types).
The main serialization code is based on my SilverlightSerializer which performs comparably with the inbuilt BinaryFormatter and produces smaller files with a much faster load time. The Unity version is doing more work and can’t use all of the fancy features to keep its compatibility with IOS (no ability to compile code on the fly).
Also it’s certainly worth only storing the things that matter and not things that would automatically recompute - my Angry Bots demo definitely overkills the amount of things which are saved - because I don’t really know the Angry Bots code.