Help me save my world data!

Hey hey! I want to know how to save multiple worlds. My game is a 2D game and a blocky one. I want to know how to save all the gameobjects in the world and after that you can go to a new world too. Then if you want to go back to the other world you can load it back up with each gameobject (Block) back in its same place. I have done the binary format for saving the players position. I have successfully did that. But I noticed that you can’t save anything from unity (GameObjects,Etc) and I have tried many things. I don’t know how to do this. I don’t have a script to show because I have done so many of them that failed. I just want to know how I can save a certain gameobject and it’s position and reload it anytime you want. Kind of like minecraft. Were you leave the world and you can come back to it. But my game is 2D. I have tried many tutorials online but non are even close to what I am trying to do. Also don’t give me the answer but I would like a detailed reply. So I can figure this out myself with your help! You guys are my only hope. I have been on this for over a week and this might be a simple thing but if you have known me for a bit. I tend to make think more complicated than it really is. Thanks for your time and have a great day.

HI! This would ne a good Idea if I was making a level based game. It’s a sand box game but thanks for your try!!

Here is some code that is untested, but might work. For simplicity I assume that you want to save the type of Gameobject and it’s position for every gameobject in the array GO2S.

You should run this script in an empty scene, which already contains things like the player and a light and those kinds of things.

One thing you need to do is put all the gameobjects you create in GO2S.

To save the level, call encodeData, and save the string that is returned. An easy way to do this is using
Unitys built in [playerprefs][1].

To load a new level, go to the almost empty scene (or destroy all the gameobjects in GO2S), get the string you previously saved, and call decodeData.

GameObject[] GO2S;// contains all gameObjects that you want to save

    public string encodeData() {
        string data = ""; //We'll put all the info in here

        for (int i = 0; i < GO2S.Length; i++) {
            int type = -1; //initializing what gameObject you have
            if (GO2S*.name.Equals("Wood")) {//find something that clearly distinguishes your GOs*

type = 0;
if (GO2S*.name.Equals(“Stone”)) {*
type = 1;
data += type + “|”; //the “|” lets us know where one piece of info begins/ends
data += GO2S_.transform.position.x + “|” + GO2S*.transform.position.y;
data += “/”; // let’s us know where we start encoding each GO
return data;
public void decodeData(string s) {
string[] GOStrings = s.Split(‘/’);//split it at the markers
for (int i = 0; i < GOStrings.Length; i++) {
string[] parameters = s.Split(‘|’);//the array contains all our variables in string form
//A thing you might also want to do is check if the String is saved properly, so you don’t end up with Indexoutofbounds exceptions*

int type = int.Parse(parameters[0]);
float x = float.Parse(parameters[1]);
float y = float.Parse(parameters[2]);
Vector3 position = new Vector3(x,y,0);
if (type == -1) {//unrecognized Gameobject
if (type == 0) {
Instantiate(woodPrefab, position,Quaternion.identity);
if (type == 1) {
Instantiate(stonePrefab, position, Quaternion.identity);