I have done my share of database reading and writing, for small projects only.
Right now I‘m faced with having to write rather complex data to a relational database, including dynamic length dictionary key-value pairs, other objects, sprites, implemented.
for the sprite i will just use a string with the path to the icon file, i guess, but i am really questioning how to best deal with interfaces implemented and objects referenced in the class to be written to the db, as well as complex types like dictionaries.
(Workaround)
After doing a lot of research I have now found different ways of realizing this:
Working: JSON.NET
Compatible with basically all .NET Runtimes, including 4.X
Allows for serializing (mostly) anything including polymorphism, generics, interfaces etc. into Json string.
That json string can then be stored in db and deserialized to an object from the string.
Optimal: Odin Serializer
Specifically tailored to Unity, allows for serialization of virtually anything, easy to use. Can serialize to byte stream and json string, highly performant
really surprised nobody commented anything about those.
Uhm sorry for asking, but why do you use a database then? Storing already serialized data into a database doesn’t seem to make any sense. You can not use any of the DN features since you only store a json string in it. Are you sure you know why we use databases? SQLite especially isn’t that optimised for speed. It just brings DB functionality in a portable format that doesn’t require a server.
We can’t really answer your question since we don’t know anything about how the data is structured on the Unity side and how your DB layout looks like and what kind of queries you might need on the DB. The most important thing about a database is the database design. However that highly depends on the requirements, relations between your data and the general usage / purpose of that data.
Im using my database for dialogue and quest content. My quest and dialogue structure uses only primitive types.
therefore i am just using my db implementation to also store my items.
it‘s not perfect, but it works. Of course i am losing a lot of the benefits, but i worked around it by having the serialized string be one field in the table, with important primitive object data in additional fields, as to still be able to retrieve the data im looking for.
Roughly like this:
id |name|prefix|suffix|lvlreq|serializedobject
that way i have all the accessors i need while still having all complex types available in the serialized object.
Heya, I am about to start up database for my game too. I used LiteDB in the past for non game projects and was very happy with it. It’s document database that acts a lot like SQLlite and works out of the box in recent versions of unity. From what I hear at least - yet to try it myself.
I am strongly leaning towards document database instead of SQL to avoid pulverizing my data into tables, just store json.