How do you save/load levels in unity???

Hello

I followed a tutorial to save/load data - but it was pretty terrible and covered nothing for most of the hour other than very basics. I am trying to save a class of my level that i create at run time so it has references to game objects. But i can’t seem to serialise game objects?

How is this sort of thing normally done?

I’ve read that but it doesn’t say how to save a game level ? I don’t have prefabs i create the level at run time in a level editor. So the game object(s) are not a prefab in the prefab folder.

Oh ok, sorry I misunderstood I thought you meant variables.

What I usually do is, loop through anything that might have been changed in scenes (for instance, doors that are opened, progress that has been made, objects placed/picked up) and then take down positions/variables that need saving, and write those out to like a “changes” file basically.

Later, when you return to the level you have to read the file in and check if the default items need moved/removed or interacted with somehow, based on the results of the file. I don’t usually actually save the “scene” per say ya know, but just where X object is located, its rotation, and whatever important variables might need tracked, if the object has a special color or texture applied… things like that.

Think you might still be misunderstanding, my fault, i poorly explained!

Think of the Sims house building creator.

So i have a House class which stores tiles and walls in arrays and thats easy to serialize. The problem comes that the house class has a reference to a class that is attatched to the house game object. And in that class it has references to game objects in the house which i can’t seem to serialize.

For example i have my house class which has a method called Create, so when i make a new house it’ll create a new game object in the world and that game object has a class House Data which is shown below:

using System;
using UnityEngine;
[Serializable]
public class HouseData : MonoBehaviour {

    public House house { private set; get; }

    public GameObject gameObject_interior;
    public GameObject gameObject_exterior;

    public void Assign(House house)
    {
        this.house = house;
    }
}

The House class has a reference to HouseData and HouseData has a reference to House so they are all connected nicely.

But when i try to save i get:

Type UnityEngine.MonoBehaviour in assembly UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null is not marked as serializable.

Ohh yes, I’m not sure how I failed to read that right twice :stuck_out_tongue:

Anyway, I can’t help in this specific case, I’m sorry! I hope somebody can point you in the right direction.

Ah okay :frowning: