I need to save and load GameObjects. How do I do this?

I have tried saving and loading through playerprefs, but I don’t want the save to be stored in the registry. I tried serialization, but it doesn’t work for gameObjects. I have even tried the Unity Serializer, but it does not work either since in my game, objects are being created and destroyed all the time. In my game, the player places newly instantiated wall sections in a multidimensional list. I need to be able to save where all the wall sections are with their rotations and materials. Is this even possible?

This isn’t really an answer just a suggestion. I am currently in the works for the same setup. The best solution I have found is if you’re making a game where players cannot access files then you should store everything in a database. If you wish to store GameObjects, then the best solution would be to store all the data for the GameObject’s via MySQL database or similar. Goto youtube and search Unity3d with MYSQL and you’ll get a bunch of tutorials on how to do this some even with gameobjects. The other way (if u dont care if players can access the files) then instantiate prefabs and make the gameobjects into prefabs.

Edit: Link to my free Save & Load Utility: SerializerHelper

Unity Serializer should work ok with instantiated objects (if you give the prefabs a Prefab Identifier). It seems to break down then and now, however.

It’s true that you can’t serializer things like GameObjects, Vector3s and Materials. However, workarounds are usually pretty easy. A position and rotation can just be represented as three integers (like posX, posY, posZ), Materials? Just save the Material name and/or file path in a string, and load it again when loading a saved game with Resource.Load. A GameObject can be represented with an unique ID int, and to load an instantiated GO you can save it’s name and then look up this name in a dictionary that lists all names and the corresponding GO filenames in your project folder.

These are just examples, and it’s how I do it and it worked well thus far. The multidimensional list needs to be flattened when serializing it, of course, and made multi-dimensional again after deserializing, but that’s also easy.

You can directly serialize GameObject using our plugin Runtime Serialization for Unity. Its not just another serialization plugin which works only on custom c# objects. But what makes it special is its capablity to serialize Unity Objects like GameObject, MonoBehaviours, Textures, Prefabs etc. For more info about supported list, please check this 2.