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

Discussion and help for Easy Save 3
Post Reply
robotSmith
Posts: 39
Joined: Thu Apr 01, 2021 4:53 pm

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

Post 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!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

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

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
robotSmith
Posts: 39
Joined: Thu Apr 01, 2021 4:53 pm

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

Post 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?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

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

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply