How to store data?

Hi. I need store data that will the code memory. For example: You are playing game and you need to save your position, but you can't obviously store that in code. Where should I store data?
9 Replies
♡Mr. L0stík♡
♡Mr. L0stík♡OP14mo ago
I thought JSON can help me, but it's too hard.
Angius
Angius14mo ago
A JSON file should be perfectly fine Make a class to represent your saved data Then File.ReadAllText() to read the file, JsonSerializer.Deserialize<TheClass>() to turn it into an instance of the class JsonSerializer.Serialize() and File.WriteAllText() to save the changed settings Ez
♡Mr. L0stík♡
♡Mr. L0stík♡OP14mo ago
Okay, do you have some good tutorial? I just need to get number of level and then re-write to new And I can't find some good tutorial for just this
Angius
Angius14mo ago
Quite literally just what I wrote could serve for a tutorial
class Settings
{
public int Foo { get; set; }
}

var read = File.ReadAllText("settings.json");
var settings = JsonSerializer.Deserialize<Settings>(read);

settings.Foo = 69;

var write = JsonSerializer.Serialize(settings);
File.WriteAllText("settings.json", write);
class Settings
{
public int Foo { get; set; }
}

var read = File.ReadAllText("settings.json");
var settings = JsonSerializer.Deserialize<Settings>(read);

settings.Foo = 69;

var write = JsonSerializer.Serialize(settings);
File.WriteAllText("settings.json", write);
'Ere
♡Mr. L0stík♡
♡Mr. L0stík♡OP14mo ago
Ok, thanks
nukleer bomb
nukleer bomb14mo ago
Yeah, JSON is the easiest way to go. But if you have a lot of data and need to be compact and performant, then you can try using some binary serializer
nukleer bomb
nukleer bomb14mo ago
GitHub
GitHub - Cysharp/MemoryPack: Zero encoding extreme performance bina...
Zero encoding extreme performance binary serializer for C# and Unity. - GitHub - Cysharp/MemoryPack: Zero encoding extreme performance binary serializer for C# and Unity.
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
nukleer bomb
nukleer bomb14mo ago
MessagePack is still better if you need to interop with other languages

Did you find this page helpful?