How to create a save system for a sandbox survival game?

I want to create a save system for my game. It needs to be able to save player stats, such as health, stamina, strength, position, rotation, etc, the terrain, and the stats of all creatures that have been loaded, such as their health, strength, position, rotation, etc. When a creature is unloaded, I want it to be temporarily saved, and when terrain is unloaded, I want it to be temporarily saved as well. When the player presses the save button, or save and quit button, it needs to permanently save everything. I am operating on a budget of 0$, so I can’t use Easy Save. Does anyone know how I could do this?

Get the data you care about and write it to disk.

Asinine comments aside, that’s what save games boil down to. Get the data, write it out. In the context of Unity, seeing as you can’t simply serialise the state of everything as-is, you need to design an architecture to manage this. This is where most of your work is going to be.

And seeing as saving is probably the most important feature in any game, you need to design with this in mind from day 1.

This is extremely well-traveled ground. Apart from the 23 million hits on google…


There are also these notes:

Load/Save steps:

An excellent discussion of loading/saving in Unity3D by Xarbrough:

Loading/Saving ScriptableObjects by a proxy identifier such as name:

When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object.

Instead you must first create the MonoBehaviour using AddComponent() on a GameObject instance, or use ScriptableObject.CreateInstance() to make your SO, then use the appropriate JSON “populate object” call to fill in its public fields.

If you want to use PlayerPrefs to save your game, it’s always better to use a JSON-based wrapper such as this one I forked from a fellow named Brett M Johnson on github:

Do not use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

Duh, that’s obvious. But HOW do I write it out?

This all goes way over my head, it makes no sense, and nothing explains it in enough detail for me to understand this. They all expect you to be quite experienced in coding, which I just barely began a handful of months ago. I did a little before that, but I had no clue what the heck I was doing, and frankly, for most semi advanced topics, still don’t. The links either didn’t tell me how, or they didn’t explain in enough detail for me to understand. And you don’t need to be rude.

There’s no way to answer that. It will vary wildly from project to project and requires a good understanding of large-scale project architecture.

Because it is an advanced topic, so is making an open world game.

It’s not something that can be explained succinctly in a forum post as it’s something you’ll have to learn over a prolonged period of time. The first part to start is the beginning, and the beginning should be small. Make a save-load system for a much smaller, isolated project. Use that knowledge and build upon it.

I searched on the asset store and found 87 free options. Not sure how good they are, but give it a browse and maybe you’ll find something that will work for you.

Nobody here can type something to “press into” your brain how to do this.

You have to learn it by doing it. Here’s how:

Steps to success:

  • pick ONE load / save tutorial on Youtube
  • do it until you see the point where they write the data out
  • go back and understand how / why / what

Remember the two-step tutorial process

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Oh, lol, no wonder I couldn’t find these, I had the wrong filters! :slight_smile: Thanks!

Probably the reason it “makes no sense” is that you’re trying to take too many steps at once. There’s a lot going on in a saved game system, and you’ve said you only started coding recently.

Start simple. Can you write some text out to a file, and then read it back in and display it in the Unity Console tab? Can you write a float variable to a text file, then read it back into a float with the correct value? This is first principles stuff. Even if you end up using a library which does the reading and writing for you, if you don’t take the time to understand the absolute basics then it’s just going to keep going way over your head.