A
A
Alexey2019-01-06 22:27:00
C++ / C#
Alexey, 2019-01-06 22:27:00

How do I do serialization and deserialization in the game?

I'm new to Unity so I started with a text quest. I ran into a problem that I can’t save and load the game, I wanted the player (reader, I don’t know how to describe it) to be able to save or load on any page, I already created a pop-up panel with buttons, but I didn’t figure out how to save from loading, please help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2019-01-06
@GavriKos

Have you already read about the PlayerPrefs class?
I advise you - write your status to some class of yours, then convert it to json, then save json through PlayerPrefs. Well, the reverse process is the same...

S
shai_hulud, 2019-01-07
@shai_hulud

After playing with PlayerPrefs, I advise you to find a good JSON serializer on the asset store and save saves to files at https://docs.unity3d.com/ScriptReference/Applicati...

K
Konstantin Kitmanov, 2019-01-07
@k12th

First and foremost, the state of the game must be described by a POCO class (or classes) that does not inherit from MonoBehavior. The easiest way to debug it is to serialize it to JSON (there are plenty of examples on the net), and write either to PlayerPrefs or to a file (this is not much more difficult, but the user will be able to send you his save if something breaks).
And if the game is designed for one session, then you can store the state in a ScriptableObject.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question