Forum rules - please read before posting.

Help: How to save/remember List<object> data?

Hi,

I have a "Cloth" scriptable object to define a player cloth (e.g. shirt, coat..) with fields such: model, material, List, List..

There will be a lot of "Cloth" assets in the game, but the player wont have access to to a cloth until he collect/earn it. Same for each cloth optional materials/mods, there will be a few for each cloth , but the player wont have access until he collect/earn it.

When the player collected a cloth/optional cloth material/mod, it's being added to his collection (a list of "Cloth" assets references , managed in a scene object script) ,then he can choose from his collection what cloth to wear, and set the cloth optional data (materials, mods) if exists/collected.

When saving the game,
how can I save what clothes does the player currently have in his collection and what optional data does each cloth currently have, Integrated in the AC saveSystem?

Thanks,
Greetings,
Shayk.

Comments

  • edited August 2020

    It's possible to save global data by using a global String variable to store a serialized version of that data just before saving - and then deserializing it afterwards upon loading.

    A tutorial on this can be found here.

    If this data is only ever associated with the Player, you could potentially rely on a Variables / Remember Variables pair of components on the Player prefab instead.

    On the topic of List data, you'll need to write a pair of functions that condense / expand the data you want to save to/from a string.

    You'll want this string to be as simple as possible, so you'll first want to find a way to save references to your SOs, rather than saving all their data directly. For example, if each SO had a unique ID, you could store a List of all such SOs held by the Player by separating their IDs with an underscore:

    1_2_12_14_6
    

    And then, when loading, you'd split this string into an array again using an underscore separator, and use that to rebuild your List of IDs.

    For optional data associated with each SO, you could either rely on a separate string variable for each "data set", or incorporate it into the same string with another separator:

    1:Red_2:Green_12:Blue_14:Blue_16:Red
    

    AC does this itself quite frequently when handling complex data. For an example, have a look through the RememberAnimator.cs script - which does this to store Animator Parameter data.

  • Thanks a lot for your detailed answer, it helped me solving the issue.
    I didn't use the variables, but I wrote a custom Remember script for the clothes collection (using your tips about the string implementation), and it works.

    Appreciate your effort.
    Thanks again.
    Shayk

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.