Save/load destroyed objects and inventory

Discussion and help for Easy Save 3
Post Reply
Tom
Posts: 1
Joined: Tue Jul 13, 2021 11:31 am

Save/load destroyed objects and inventory

Post by Tom »

Hello.
I am still pretty new at unity and also programming so I’m having some trouble getting ES3 to work as a want it. So for I managed to save player position and having multi saving/loading slots. Now I can’t figure it out, how to save destroyed object. I went through the docs but can’t figure it out. Script that I found in an old topic doesn’t work for me also, because destroyed object are not loaded in every other saved game and even if I start the new game object with this script that I destroy in previous run are destroyed. To bear in mind I’m still learning so I don’t understand every aspect of this script.

Code: Select all

public class SaveDestroyed : MonoBehaviour 
{
	public string guid = System.Guid.NewGuid().ToString();
    static bool isApplicationQuitting = false;

	void Start () 
	{
		if(ES3.KeyExists(guid))
			Destroy(this.gameObject);
	}

	void OnDestroy()
	{
        if (gameObject.scene.isLoaded && !isApplicationQuitting)
            ES3.Save<bool>(guid, true);
	}

    void OnApplicationQuit()
    {
        isApplicationQuitting = true;
    }
}
Also any idea how to save/load inventory system. There is one script in my project where is listed what is in my inventory. Is there any way to save/load this script or do I need to make it somehow different?

Any suggestion would be nice. Thank you!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save/load destroyed objects and inventory

Post by Joel »

Hi there,
Script that I found in an old topic doesn’t work for me also, because destroyed object are not loaded in every other saved game and even if I start the new game object with this script that I destroy in previous run are destroyed.
I'm afraid I'm struggling to understand what you're saying. Please could you clarify? Do you mean your objects are instantiated at runtime?
Also any idea how to save/load inventory system. There is one script in my project where is listed what is in my inventory. Is there any way to save/load this script or do I need to make it somehow different?
This would very much depend on how you've coded your inventory system. However, I recommend looking at our guides to see how Easy Save can be used to save and load data, and what types of data are supported:

https://docs.moodkie.com/product/easy-s ... s3-guides/
https://docs.moodkie.com/easy-save-3/getting-started/
https://docs.moodkie.com/easy-save-3/es ... ted-types/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply