Page 1 of 1

What are the best practices for using player actioned Save and Load (buttons)?

Posted: Sat Apr 03, 2021 7:25 pm
by robotSmith
Hello hello,

In my game the player chooses when to Save and when to Load. I am wondering how are other people doing this and if there are best practices or common ways other people chose to deal with this.

Right now my approach is this: The player can save (or load) whenever they want using a Save button. Now, I have this Save button invoke an Action (event) in which each object that needs save/load has registered to using "+=". Now, this works fine most of the time, but there can be some dependencies around where I need something loaded first. I could use the Script Order option in Unity, but I'd prefer not to modify it if I have to. Any other options?

TIA!

Re: What are the best practices for using player actioned Save and Load (buttons)?

Posted: Sat Apr 03, 2021 7:40 pm
by Joel
Hi there,

The best way to manage this very much depends on the structure of your project. However, the most common structure is to have one script which manages all of the saving, rather than getting individual objects to save themselves. This may also make it easier to ensure that dependencies are saved in a predictable order.

All the best,
Joel

Re: What are the best practices for using player actioned Save and Load (buttons)?

Posted: Sun Apr 04, 2021 7:10 pm
by robotSmith
Joel wrote: Sat Apr 03, 2021 7:40 pm Hi there,

The best way to manage this very much depends on the structure of your project. However, the most common structure is to have one script which manages all of the saving, rather than getting individual objects to save themselves. This may also make it easier to ensure that dependencies are saved in a predictable order.

All the best,
Joel
Thanks for the prompt reply Joel.

I'm trying to wrap my head around this. I guess if there is a save manager, each object will manage their own loading states from what you have seen?

Re: What are the best practices for using player actioned Save and Load (buttons)?

Posted: Sun Apr 04, 2021 7:16 pm
by Joel
Hi there,

The manager would do the saving and loading, not the individual objects, otherwise this negates the benefit of having a manager.

The simplest example of a manager would be this:

Code: Select all

public class Manager : MonoBehaviour
{
	public GameObject[] gameObjectsToSave;
	
	void Save()
	{
		ES3.Save("gameObjects", gameObjectsToSave);
	}
	
	void Load()
	{
		if(ES3.FileExists())
			gameObjectsToSave = ES3.Load<GameObject[]>("gameObjects");
	}
}
All the best,
Joel