Verification for saving a list of ScriptableObjects

Discussion and help for Easy Save 3
Post Reply
Rdbk
Posts: 35
Joined: Sun Jun 09, 2019 3:58 pm

Verification for saving a list of ScriptableObjects

Post by Rdbk »

I recently bought Easy Save and got it working for me after some fiddling. Being new to it (and Unity in general), I was wondering if someone could take a look at how I have it set up and if that is the proper way or if there is a more optimal solution.

My game has a character roster (think XCOM) with randomized unique characters and you can choose up to 4 of them to be part of your mission team. Each character has an instance of ScriptableObject that holds their unique stats (ints), a reference to their portrait (sprite) and also references to their skills (ScriptableObjects). I haven't set up saving for the roster yet, but for the mission team I have set it up like this: Characters in mission team have their ScriptableObject added to a list. I then loop through that list and ES3.Save each as "'TeamMember' + i". Then I also save the list.Count as "TeamSize". So for a full 4-man team, I have 5 saved values. As for loading, I first initialize the mission team list and then load the "TeamSize" as int. I use that int as the loop count for a for loop that ES3.Loads "'TeamMember' + i" and adds that character to the initialized mission team list. Then as the final step I destroy current UI Character Bars and instantiate new ones based on the mission team list.

This seems to work great so far. Do you see problems with this way of doing it or how it could be improved? Originally I tried to just save the mission team list, but that didn't work.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Verification for saving a list of ScriptableObjects

Post by Joel »

Hi there,

That indeed seems like a suitable way of doing it.

Saving the List probably won't work in your case because there is no fixed instance ID for the ScriptableObjects, so they can't be saved or loaded by reference. If you did want to save the List, you can use the ES3.LoadInto method, which accepts an existing List of ScriptableObjects. This will load the data into the ScriptableObjects you provide as a parameter, rather than creating new instances of the ScriptableObjects.

However, if your current method is working fine, I would stick with that :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Rdbk
Posts: 35
Joined: Sun Jun 09, 2019 3:58 pm

Re: Verification for saving a list of ScriptableObjects

Post by Rdbk »

Thanks for the confirmation Joel! I tried testing it again and doh... I am able to save/load the list directly both with LoadInto and the default Load. The problem was that earlier I tried to first assign the list to a new instance of a class and then save that instance with easy save. Don't know why I tried that instead of directly saving the list with easy save... Oh well, now I can choose from 3 different working ways of doing it :D

Although now I have a different problem, but I created a separate topic for it (https://moodkie.com/forum/viewtopic.php?f=13&t=1661)
Post Reply