In-game database that accepts user input

Hi all,

I’m looking into having a database that the user can input into, like an in-game editor window loading to an scriptableobject asset. Building a roleplay tool, so though I could build the entire database in the editor I’d like the option of people being able to input their own data for say items, enemies etc. without the need of using unity directly.

I’ve come across the concepts of scriptable objects, I/O and serialization techniques and was after some suggestions on best practice to incorporate this functionality (using any of the above or none of the above!).

Thanks.

I’m a big fan of XML personally- writing to and reading from an XML file is incredibly easy and the data is guaranteed to persist between game sessions.

Ah yes, knew I missed something off the list. Thanks. Would that be a something which you could merge files together easily too. So user A creates a new item, user B accesses that database and adds new item to their collection?

What about creating model sections. So user has a selection of prefab game objects (tiles with properties such as move cost, props such as tables with durability, doors with open/close interaction). They can configure these into there own rooms/building/other set and then use that set to place on a map.

Local position would be easy enough to store, what would be a way to store the correct objects. A reference to a gameobject itself or item IDs? Or once again something smarter?

Just to verify, you’re not talking about network or internet access to a shared data storage medium right? That’s an entirely different bag of worms. As long as we’re on the same page and just talking about different ‘users’ using the same computer/digital copy of the program, that’s good.

You don’t necessarily have to merge files in the way that you’re thinking: if you have a file you create called “ItemDatabase.xml” or something, that file can get accessed and added to and it wouldn’t know (or care) which user is doing the editing. You could also make user-specific databases too. Remember that how things look and how they really are can be two completely different things, so even if you have user-specific databases for items and no “master” database with all of the data, it could LOOK in the program as if there’s a master-database because you can load all of the user-databases into a collective dictionary variable or w/e on start.

As for the “model sections”, that’s not very hard either. All you would have to do is have a “tile” class or something similar that holds all of the data you need, then when saving it to XML just tag and organize the data in a way that makes sense. There are literally dozens of ways to organize it, so write it out visually first to find out how maybe you’d like to see the data listed, like so:

<user name = "some user name">
    <tile parameter1= "some value" paramater2 = "some value" parameter3 = "some value">
    <tile parameter1= "some value" paramater2 = "some value" parameter3 = "some value">
</user>

or you could go more like this:

<user>
    <name = "some user name">
    <tile>
        <parameter1>some value</parameter1>
        <parameter1>some value</parameter1>
    </tile>
    <tile>
        <parameter1>some value</parameter1>
        <parameter1>some value</parameter1>
    </tile>
</user>

It’s literally just up to you and how you want to load the data later- XML is pretty flexible. You shouldn’t store GameObject references though- you’d be better served storing some int or enum value or something that references a specific spot in a list or database. Remember: what you’re saving in the XML file… it doesn’t need to have all of the inner bits, just the bits that are changable within that blueprint (the parts that are different from one instance of the “tile” you’re referencing and a different instance used by someone else, like position data). The tile’s blueprint itself would be defined in your code- it doesn’t need to be redefined in the save data.

1 Like

That’s great. Really helped to put those first inklings of the concepts into something that makes sense. And yeah, exactly on the same page, just accessing local files. I think I’ve got a long way to go before I start looking at networking and all the joys. Start with learning some XML stuff first.

Thanks a lot!