How to save Scriptable Object as value, not by reference?

Discussion and help for Easy Save 3
alchemist_wurzel
Posts: 5
Joined: Fri Nov 26, 2021 11:35 am

Re: How to save Scriptable Object as value, not by reference?

Post by alchemist_wurzel »

I see! Not providing ES3Settings yields the same result though. I get the correct File Names with ES3.GetFiles, it just seems that the deserialized object that's added to the list is always the same so it gets overriden every time I deserialize in the for loop and I don't understand why that happens.

EDIT:
I made it work with the following code:

Code: Select all

        public List<T> LoadFilesAtPath<T>(string _strPath) where T : ScriptableObject
        {
            List<T> liFiles = new List<T>();
            string[] arFileNames = ES3.GetFiles(_strPath);
            for (int i = 0; i < arFileNames.Length; i++)
            {
                byte[] arFileAsBytes = ES3.LoadRawBytes(Path.Combine(_strPath, arFileNames[i]));
                //T file = ES3.Deserialize<T>(arFileAsBytes);
                T file = ScriptableObject.CreateInstance<T>();
                ES3.DeserializeInto(arFileAsBytes, file);
                if (file != null) liFiles.Add(file);
            }
            return liFiles;
        }
So I think I will do it this way for now. Thank you!
Post Reply