Save level infos as binary file using C# POCO-classes

Godot Version

4.2.1

Question

Hello :). I’m trying to save level infos of my game in a binary file using C# and this is driving me crazy :).

Basically I want to save these infos for each level:

   private Type mLevelType;
    private bool mUnlocked;
    private bool mPremium;
    private int mNumberOfPlays;
    private int mStars;

There will be hundrets of levels at the end, so I want so save these infos as an array or within a wrapper-class.
I’m using simple POCO-classes and I don’t need and I don’t want to inherit from Godot.GameObject, Resource ect. (I just have one Scene with dynamic content generated for each different level. So saving the scenes is not an option.)

Since I’m using POCO-classes I can not use FileAccess.StoreVar or ResourceSaver. Does anybody has a good advice how to store my data?
Should I use a BinaryFormatter? If yes, how can I save my file in the “user://” directory?

Perhaps the LiteDB project would help you. I’ve had a similar use case in the past and tried it for my c# file storage needs and it worked out great. It has a blob data type, or it will do a good job of serializing your custom structs for you. It would wrap all those values up into one .db file for you and you could query their values like a SQL db if you’d like, or just grab them all into an array.