Saving a Large Number of GameObjects to XML

I’m working on an app that’s more or less a grid based map maker. The user places tiles on a “table” and makes their map.

I can’t, for the life of me, wrap my head around XML Serialization. I’ve tried two free assets on the store for just such a thing, but unfortunately they’re out of date (The first one doesn’t handle sprites, the second doesnt have functioning examples). I have two choices, give up or do it myself. Since I didn’t write 90% of the code just to stop at the last major feature I’m trying to find some tutorials on scene saving with unity.

I did find a few text/web tutorials (and the one on the wiki) but they didn’t answer my question: how do I save a GameObject (Prefab of a sprite) and later load it? I really just need it’s position and rotation. Before this I’ve always worked with/around the limits of player prefs. However, I’m going to have a significant number of GameObjects (2k+). I’m hoping for a tutorial that will simply demonstrate saving two+ objects and reloading them, but I’ll take any help or advice I can get.

If they’re prefabs then place them in a Resources folder and save the path to that prefab along with the position and rotation. This will allow you to load by path/name at runtime easily.

Position and rotation can be represented by Vector3 but that won’t serialize out of the box for you. What I did was make a Vec3String class that saves a Vector3 out as a string and can reconstruct it at runtime. Since a Vector3 is just 3 float values, it’s pretty trivial to implement.

Also consider asking yourself if XML makes sense as a way to serialize. XML is the current thing that comes to mind when people want to dump stuff to a file, but it is rather cumbersome if you don’t need it.

Would a CSV text file work better?
Would a json type format work better?
Would saving pure binary data work better?

All of those are easier to parse/work with if you don’t need XML

Okay, something may have just clicked for me. I’m going to give it a go and see how miserably/hilariously I fail. Thanks for your time.

Edit:
Jackmott, I don’t know. This is an app for mobile devices and PC/etc are just after thoughts.

I would personally disagree with this sentiment, but that’s just me.

However - if you’re working in a mobile platform you’re going to run into issues loading and saving files at runtime unless they’re remote and you’re using WWW. Just something to keep in mind.

Can you elaborate on this? I know on Android I have to force to SD card in order to write to the file system at all. Writing to WWW isn’t…desired or necessarily practical. I really just need them to Make their map and store it on their device so they can load it later. Requiring internet access (tablets) is against specs.

I don’t work in mobile so I’m not the best person to elaborate but if I understand correctly, a lot of the System.IO stuff is locked down on mobile.

I’ve used StreamReader and File to read a json on ios and android before, with no problem, but beyond that I can’t say for sure