0

I have a problem with saving a game session. Here's some JSON fragment from the saved data.

"boughtSpells":[{"instanceID":13864},{"instanceID":13421}]

And here's some code.

[CreateAssetMenu(fileName = "New Spell Pattern", menuName = "SpellPattern")]
[System.Serializable]
public class SpellPattern : ScriptableObject {
    public string spellName;

    [TextArea]
    public string spellDescription;
}

Game data model.

[Serializable]
public class GameData
{
    public List<SpellPattern> boughtSpells;
}

I think it saves a reference of Unity's Scriptable Object ID(which is unique, but not persistent), rather than serializing the data in it. I need to serialize the data correctly, but I have no idea how to make it with Unity's Scriptable Objects, but at the same time I don't want to change the architecture of these Scriptable Objects.

1 Answer 1

1

Scriptable objects are not meant to be edited at run time. The purpose of Scriptable Objects is: -for saving and storying the data during an editor session e.g. an Inventory system -for having an asset which is shared by various systems

For saving data models at run time I recommend you to use Structs.

In case you need to save game state/session you can use PlayerPrefs and if the data you want to save is not plain int or string, you should serialise it in form of byte files using Binaryformatter and save it to the memory(Application.PersitentDatapath maybe).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.