2
\$\begingroup\$

I am using ScriptableObject to save state of my game. Currently Saving: - Selected object - Object count

It works fine in editor, but when I make a PC build the data doesn't saves and everything I launch the PC build the game is in default state.

My GameConfig ScriptableObject is located in the Resources folder, can anyone help out exactly what the issue can be? The scriptable object is serialized and so are the fields in it.

Unity version: 2017.3.1p1

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

Sorry, but ScriptableObject's don't work that way. They conceptually are game assets. You can modify and save assets in edit mode, but you can not do that in a built game executable. The executable does not even contain the code necessary for writing asset files. So you will have to find a different way to implement savegames.

When your save data is rather small or if you want to support platforms without a writable filesystem (like HTML5) , you can use PlayerPrefs for this, which allows you to read and write key/value pairs which get persisted in a platform-appropriate manner.

When your savegames are too large to be handled with PlayerPrefs, then you will have to invent your own savegame format and save data to the user directory using the standard C# classes for file access like StreamWriter / StreamReader (for text-based formats) or FileStream (for binary-based format).

\$\endgroup\$
1
0
\$\begingroup\$

I suggest you don't use .txt IO approach, It will not carry over to your build. use this code out test it out

https://github.com/comphonia/UnityAssetsandScripts/wiki/Read-and-Write-Data-to-a-Text-File-in-Unity

If you're looking for a scalable solution try Firebase(beta) or setup a server database.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .