Saving/Loading not working in build.

Discussion and help for Easy Save 3
Tentakero
Posts: 15
Joined: Wed Oct 14, 2020 10:00 pm

Re: Saving/Loading not working in build.

Post by Tentakero »

Ok! Sigh of relief. I managed to get it all working with the database method.

To anyone that has this issue in the future, here's what I did.

Step 1: Create a custom editor tool that searches your game assets for a specific type of script. In my case, I'm searching for Items and all of their inherited classes such as ToolItems, SeedItems, etc.

Code: Select all

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(ItemDatabase))]
public class ItemDatabaseEditorExtension : Editor
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        ItemDatabase database = (ItemDatabase)target;
        if(GUILayout.Button("Update Item Database"))
        {
            if(database.itemDatabase.Count > 0)
            {
                database.itemDatabase.Clear();
            }
            Debug.Log("Updated Item Database Database");
            string[] guids;
            guids = AssetDatabase.FindAssets("t:Item");
            foreach (string item in guids)
            {
                database.itemDatabase.Add((Item)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(item), typeof(Object)));
            }
        }

        EditorUtility.SetDirty(database);
    }
}
Step 2:Create a ScriptableObject that will act as a database for your items.

Step 3:Right click and add this database scriptable to the ES3 reference manager.

With this, the game was able to find any of the necessary item data at runtime and load properly.

I have one last question for Joel! Is it possible to convert the ES3 reference manager into a prefab and manually handle whatever references are needed? I am primarily using the LoadInto method with most of the stuff I am saving and tend to load data directly into object scripts. The soil plots for example are saved as a list of objects in a scene. With a prefab I may be able to just work with a single master reference manager, but I'm not sure if that'll cause problems some situations.

For example: If the player is able to create more soil plots at run time, would references to these be needed if I'm already referencing it's parent list? Soil plots would be added to said list, instead of referencing the object itself?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving/Loading not working in build.

Post by Joel »

It's not possible to turn the reference manager into a prefab because it needs to reference items within the scene. However, creating your own prefab with a script with a variable/array that references anything that you'll want to store by reference and ensuring this is in your scene prior to runtime will ensure that the references are automatically added to the manager.

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